Commit | Line | Data |
---|---|---|
3de7a1dc TV |
1 | /* |
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> | |
355b200b | 30 | #include <linux/module.h> |
b9eb5d7d | 31 | #include <linux/semaphore.h> |
3de7a1dc TV |
32 | #include <linux/seq_file.h> |
33 | #include <linux/platform_device.h> | |
34 | #include <linux/regulator/consumer.h> | |
3de7a1dc | 35 | #include <linux/wait.h> |
18946f62 | 36 | #include <linux/workqueue.h> |
40885ab3 | 37 | #include <linux/sched.h> |
f1da39d9 | 38 | #include <linux/slab.h> |
5a8b572d | 39 | #include <linux/debugfs.h> |
4fbafaf3 | 40 | #include <linux/pm_runtime.h> |
3de7a1dc | 41 | |
a0b38cc4 | 42 | #include <video/omapdss.h> |
7a7c48f9 | 43 | #include <video/mipi_display.h> |
3de7a1dc TV |
44 | |
45 | #include "dss.h" | |
819d807c | 46 | #include "dss_features.h" |
3de7a1dc | 47 | |
3de7a1dc TV |
48 | #define DSI_CATCH_MISSING_TE |
49 | ||
3de7a1dc TV |
50 | struct dsi_reg { u16 idx; }; |
51 | ||
52 | #define DSI_REG(idx) ((const struct dsi_reg) { idx }) | |
53 | ||
54 | #define DSI_SZ_REGS SZ_1K | |
55 | /* DSI Protocol Engine */ | |
56 | ||
57 | #define DSI_REVISION DSI_REG(0x0000) | |
58 | #define DSI_SYSCONFIG DSI_REG(0x0010) | |
59 | #define DSI_SYSSTATUS DSI_REG(0x0014) | |
60 | #define DSI_IRQSTATUS DSI_REG(0x0018) | |
61 | #define DSI_IRQENABLE DSI_REG(0x001C) | |
62 | #define DSI_CTRL DSI_REG(0x0040) | |
75d7247c | 63 | #define DSI_GNQ DSI_REG(0x0044) |
3de7a1dc TV |
64 | #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048) |
65 | #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C) | |
66 | #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050) | |
67 | #define DSI_CLK_CTRL DSI_REG(0x0054) | |
68 | #define DSI_TIMING1 DSI_REG(0x0058) | |
69 | #define DSI_TIMING2 DSI_REG(0x005C) | |
70 | #define DSI_VM_TIMING1 DSI_REG(0x0060) | |
71 | #define DSI_VM_TIMING2 DSI_REG(0x0064) | |
72 | #define DSI_VM_TIMING3 DSI_REG(0x0068) | |
73 | #define DSI_CLK_TIMING DSI_REG(0x006C) | |
74 | #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070) | |
75 | #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074) | |
76 | #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078) | |
77 | #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C) | |
78 | #define DSI_VM_TIMING4 DSI_REG(0x0080) | |
79 | #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084) | |
80 | #define DSI_VM_TIMING5 DSI_REG(0x0088) | |
81 | #define DSI_VM_TIMING6 DSI_REG(0x008C) | |
82 | #define DSI_VM_TIMING7 DSI_REG(0x0090) | |
83 | #define DSI_STOPCLK_TIMING DSI_REG(0x0094) | |
84 | #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20)) | |
85 | #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20)) | |
86 | #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20)) | |
87 | #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20)) | |
88 | #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20)) | |
89 | #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20)) | |
90 | #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20)) | |
91 | ||
92 | /* DSIPHY_SCP */ | |
93 | ||
94 | #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000) | |
95 | #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004) | |
96 | #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008) | |
97 | #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014) | |
0a0ee46b | 98 | #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028) |
3de7a1dc TV |
99 | |
100 | /* DSI_PLL_CTRL_SCP */ | |
101 | ||
102 | #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000) | |
103 | #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004) | |
104 | #define DSI_PLL_GO DSI_REG(0x300 + 0x0008) | |
105 | #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C) | |
106 | #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010) | |
107 | ||
a72b64b9 AT |
108 | #define REG_GET(dsidev, idx, start, end) \ |
109 | FLD_GET(dsi_read_reg(dsidev, idx), start, end) | |
3de7a1dc | 110 | |
a72b64b9 AT |
111 | #define REG_FLD_MOD(dsidev, idx, val, start, end) \ |
112 | dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end)) | |
3de7a1dc TV |
113 | |
114 | /* Global interrupts */ | |
115 | #define DSI_IRQ_VC0 (1 << 0) | |
116 | #define DSI_IRQ_VC1 (1 << 1) | |
117 | #define DSI_IRQ_VC2 (1 << 2) | |
118 | #define DSI_IRQ_VC3 (1 << 3) | |
119 | #define DSI_IRQ_WAKEUP (1 << 4) | |
120 | #define DSI_IRQ_RESYNC (1 << 5) | |
121 | #define DSI_IRQ_PLL_LOCK (1 << 7) | |
122 | #define DSI_IRQ_PLL_UNLOCK (1 << 8) | |
123 | #define DSI_IRQ_PLL_RECALL (1 << 9) | |
124 | #define DSI_IRQ_COMPLEXIO_ERR (1 << 10) | |
125 | #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14) | |
126 | #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15) | |
127 | #define DSI_IRQ_TE_TRIGGER (1 << 16) | |
128 | #define DSI_IRQ_ACK_TRIGGER (1 << 17) | |
129 | #define DSI_IRQ_SYNC_LOST (1 << 18) | |
130 | #define DSI_IRQ_LDO_POWER_GOOD (1 << 19) | |
131 | #define DSI_IRQ_TA_TIMEOUT (1 << 20) | |
132 | #define DSI_IRQ_ERROR_MASK \ | |
133 | (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \ | |
8af6ff01 | 134 | DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST) |
3de7a1dc TV |
135 | #define DSI_IRQ_CHANNEL_MASK 0xf |
136 | ||
137 | /* Virtual channel interrupts */ | |
138 | #define DSI_VC_IRQ_CS (1 << 0) | |
139 | #define DSI_VC_IRQ_ECC_CORR (1 << 1) | |
140 | #define DSI_VC_IRQ_PACKET_SENT (1 << 2) | |
141 | #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3) | |
142 | #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4) | |
143 | #define DSI_VC_IRQ_BTA (1 << 5) | |
144 | #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6) | |
145 | #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7) | |
146 | #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8) | |
147 | #define DSI_VC_IRQ_ERROR_MASK \ | |
148 | (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \ | |
149 | DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \ | |
150 | DSI_VC_IRQ_FIFO_TX_UDF) | |
151 | ||
152 | /* ComplexIO interrupts */ | |
153 | #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0) | |
154 | #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1) | |
155 | #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2) | |
6705615e TV |
156 | #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3) |
157 | #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4) | |
3de7a1dc TV |
158 | #define DSI_CIO_IRQ_ERRESC1 (1 << 5) |
159 | #define DSI_CIO_IRQ_ERRESC2 (1 << 6) | |
160 | #define DSI_CIO_IRQ_ERRESC3 (1 << 7) | |
6705615e TV |
161 | #define DSI_CIO_IRQ_ERRESC4 (1 << 8) |
162 | #define DSI_CIO_IRQ_ERRESC5 (1 << 9) | |
3de7a1dc TV |
163 | #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10) |
164 | #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11) | |
165 | #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12) | |
6705615e TV |
166 | #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13) |
167 | #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14) | |
3de7a1dc TV |
168 | #define DSI_CIO_IRQ_STATEULPS1 (1 << 15) |
169 | #define DSI_CIO_IRQ_STATEULPS2 (1 << 16) | |
170 | #define DSI_CIO_IRQ_STATEULPS3 (1 << 17) | |
6705615e TV |
171 | #define DSI_CIO_IRQ_STATEULPS4 (1 << 18) |
172 | #define DSI_CIO_IRQ_STATEULPS5 (1 << 19) | |
3de7a1dc TV |
173 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20) |
174 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21) | |
175 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22) | |
176 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23) | |
177 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24) | |
178 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25) | |
6705615e TV |
179 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26) |
180 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27) | |
181 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28) | |
182 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29) | |
3de7a1dc TV |
183 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30) |
184 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31) | |
bbecb50b TV |
185 | #define DSI_CIO_IRQ_ERROR_MASK \ |
186 | (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \ | |
6705615e TV |
187 | DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \ |
188 | DSI_CIO_IRQ_ERRSYNCESC5 | \ | |
189 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \ | |
190 | DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \ | |
191 | DSI_CIO_IRQ_ERRESC5 | \ | |
192 | DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \ | |
193 | DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \ | |
194 | DSI_CIO_IRQ_ERRCONTROL5 | \ | |
bbecb50b TV |
195 | DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \ |
196 | DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \ | |
6705615e TV |
197 | DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \ |
198 | DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \ | |
199 | DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5) | |
3de7a1dc | 200 | |
4ae2dddd TV |
201 | typedef void (*omap_dsi_isr_t) (void *arg, u32 mask); |
202 | ||
b7dec9b6 TV |
203 | static int dsi_display_init_dispc(struct platform_device *dsidev, |
204 | struct omap_overlay_manager *mgr); | |
205 | static void dsi_display_uninit_dispc(struct platform_device *dsidev, | |
206 | struct omap_overlay_manager *mgr); | |
207 | ||
4ae2dddd | 208 | #define DSI_MAX_NR_ISRS 2 |
739a7f46 TV |
209 | #define DSI_MAX_NR_LANES 5 |
210 | ||
211 | enum dsi_lane_function { | |
212 | DSI_LANE_UNUSED = 0, | |
213 | DSI_LANE_CLK, | |
214 | DSI_LANE_DATA1, | |
215 | DSI_LANE_DATA2, | |
216 | DSI_LANE_DATA3, | |
217 | DSI_LANE_DATA4, | |
218 | }; | |
219 | ||
220 | struct dsi_lane_config { | |
221 | enum dsi_lane_function function; | |
222 | u8 polarity; | |
223 | }; | |
4ae2dddd TV |
224 | |
225 | struct dsi_isr_data { | |
226 | omap_dsi_isr_t isr; | |
227 | void *arg; | |
228 | u32 mask; | |
229 | }; | |
230 | ||
3de7a1dc TV |
231 | enum fifo_size { |
232 | DSI_FIFO_SIZE_0 = 0, | |
233 | DSI_FIFO_SIZE_32 = 1, | |
234 | DSI_FIFO_SIZE_64 = 2, | |
235 | DSI_FIFO_SIZE_96 = 3, | |
236 | DSI_FIFO_SIZE_128 = 4, | |
237 | }; | |
238 | ||
d6049144 AT |
239 | enum dsi_vc_source { |
240 | DSI_VC_SOURCE_L4 = 0, | |
241 | DSI_VC_SOURCE_VP, | |
3de7a1dc TV |
242 | }; |
243 | ||
dfc0fd8d TV |
244 | struct dsi_irq_stats { |
245 | unsigned long last_reset; | |
246 | unsigned irq_count; | |
247 | unsigned dsi_irqs[32]; | |
248 | unsigned vc_irqs[4][32]; | |
249 | unsigned cio_irqs[32]; | |
250 | }; | |
251 | ||
4ae2dddd TV |
252 | struct dsi_isr_tables { |
253 | struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS]; | |
254 | struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS]; | |
255 | struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS]; | |
256 | }; | |
257 | ||
f1e0001f TV |
258 | struct dsi_clk_calc_ctx { |
259 | struct platform_device *dsidev; | |
260 | ||
261 | /* inputs */ | |
262 | ||
263 | const struct omap_dss_dsi_config *config; | |
264 | ||
265 | unsigned long req_pck_min, req_pck_nom, req_pck_max; | |
266 | ||
267 | /* outputs */ | |
268 | ||
269 | struct dsi_clock_info dsi_cinfo; | |
270 | struct dispc_clock_info dispc_cinfo; | |
271 | ||
272 | struct omap_video_timings dispc_vm; | |
273 | struct omap_dss_dsi_videomode_timings dsi_vm; | |
274 | }; | |
275 | ||
f1da39d9 | 276 | struct dsi_data { |
c8aac01b | 277 | struct platform_device *pdev; |
3de7a1dc | 278 | void __iomem *base; |
4fbafaf3 | 279 | |
11ee9606 TV |
280 | int module_id; |
281 | ||
affe360d | 282 | int irq; |
3de7a1dc | 283 | |
4fbafaf3 TV |
284 | struct clk *dss_clk; |
285 | struct clk *sys_clk; | |
286 | ||
a0d269ec TV |
287 | struct dispc_clock_info user_dispc_cinfo; |
288 | struct dsi_clock_info user_dsi_cinfo; | |
289 | ||
3de7a1dc TV |
290 | struct dsi_clock_info current_cinfo; |
291 | ||
2a89dc15 | 292 | bool vdds_dsi_enabled; |
3de7a1dc TV |
293 | struct regulator *vdds_dsi_reg; |
294 | ||
295 | struct { | |
d6049144 | 296 | enum dsi_vc_source source; |
3de7a1dc TV |
297 | struct omap_dss_device *dssdev; |
298 | enum fifo_size fifo_size; | |
5ee3c144 | 299 | int vc_id; |
3de7a1dc TV |
300 | } vc[4]; |
301 | ||
302 | struct mutex lock; | |
b9eb5d7d | 303 | struct semaphore bus_lock; |
3de7a1dc TV |
304 | |
305 | unsigned pll_locked; | |
306 | ||
4ae2dddd TV |
307 | spinlock_t irq_lock; |
308 | struct dsi_isr_tables isr_tables; | |
309 | /* space for a copy used by the interrupt handler */ | |
310 | struct dsi_isr_tables isr_tables_copy; | |
311 | ||
18946f62 | 312 | int update_channel; |
5476e74a TV |
313 | #ifdef DEBUG |
314 | unsigned update_bytes; | |
315 | #endif | |
3de7a1dc | 316 | |
3de7a1dc | 317 | bool te_enabled; |
40885ab3 | 318 | bool ulps_enabled; |
3de7a1dc | 319 | |
18946f62 TV |
320 | void (*framedone_callback)(int, void *); |
321 | void *framedone_data; | |
322 | ||
323 | struct delayed_work framedone_timeout_work; | |
324 | ||
3de7a1dc TV |
325 | #ifdef DSI_CATCH_MISSING_TE |
326 | struct timer_list te_timer; | |
327 | #endif | |
328 | ||
329 | unsigned long cache_req_pck; | |
330 | unsigned long cache_clk_freq; | |
331 | struct dsi_clock_info cache_cinfo; | |
332 | ||
333 | u32 errors; | |
334 | spinlock_t errors_lock; | |
335 | #ifdef DEBUG | |
336 | ktime_t perf_setup_time; | |
337 | ktime_t perf_start_time; | |
3de7a1dc TV |
338 | #endif |
339 | int debug_read; | |
340 | int debug_write; | |
dfc0fd8d TV |
341 | |
342 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS | |
343 | spinlock_t irq_stats_lock; | |
344 | struct dsi_irq_stats irq_stats; | |
345 | #endif | |
49641116 TA |
346 | /* DSI PLL Parameter Ranges */ |
347 | unsigned long regm_max, regn_max; | |
348 | unsigned long regm_dispc_max, regm_dsi_max; | |
349 | unsigned long fint_min, fint_max; | |
350 | unsigned long lpdiv_max; | |
24c1ae41 | 351 | |
d9820850 | 352 | unsigned num_lanes_supported; |
99322577 | 353 | unsigned line_buffer_size; |
75d7247c | 354 | |
739a7f46 TV |
355 | struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; |
356 | unsigned num_lanes_used; | |
75d7247c | 357 | |
24c1ae41 | 358 | unsigned scp_clk_refcount; |
7d2572f8 AT |
359 | |
360 | struct dss_lcd_mgr_config mgr_config; | |
e67458a8 | 361 | struct omap_video_timings timings; |
02c3960b | 362 | enum omap_dss_dsi_pixel_format pix_fmt; |
dca2b152 | 363 | enum omap_dss_dsi_mode mode; |
0b3ffe39 | 364 | struct omap_dss_dsi_videomode_timings vm_timings; |
81b87f51 | 365 | |
1f68d9c4 | 366 | struct omap_dss_device output; |
f1da39d9 | 367 | }; |
3de7a1dc | 368 | |
2e868dbe AT |
369 | struct dsi_packet_sent_handler_data { |
370 | struct platform_device *dsidev; | |
371 | struct completion *completion; | |
372 | }; | |
373 | ||
3de7a1dc | 374 | #ifdef DEBUG |
90ab5ee9 RR |
375 | static bool dsi_perf; |
376 | module_param(dsi_perf, bool, 0644); | |
3de7a1dc TV |
377 | #endif |
378 | ||
f1da39d9 AT |
379 | static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev) |
380 | { | |
381 | return dev_get_drvdata(&dsidev->dev); | |
382 | } | |
383 | ||
a72b64b9 AT |
384 | static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev) |
385 | { | |
1f68d9c4 | 386 | return to_platform_device(dssdev->output->dev); |
a72b64b9 AT |
387 | } |
388 | ||
389 | struct platform_device *dsi_get_dsidev_from_id(int module) | |
390 | { | |
1f68d9c4 | 391 | struct omap_dss_device *out; |
400e65d1 AT |
392 | enum omap_dss_output_id id; |
393 | ||
78e7f256 TV |
394 | switch (module) { |
395 | case 0: | |
396 | id = OMAP_DSS_OUTPUT_DSI1; | |
397 | break; | |
398 | case 1: | |
399 | id = OMAP_DSS_OUTPUT_DSI2; | |
400 | break; | |
401 | default: | |
402 | return NULL; | |
403 | } | |
400e65d1 AT |
404 | |
405 | out = omap_dss_get_output(id); | |
406 | ||
1f68d9c4 | 407 | return out ? to_platform_device(out->dev) : NULL; |
a72b64b9 AT |
408 | } |
409 | ||
410 | static inline void dsi_write_reg(struct platform_device *dsidev, | |
411 | const struct dsi_reg idx, u32 val) | |
3de7a1dc | 412 | { |
f1da39d9 AT |
413 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
414 | ||
415 | __raw_writel(val, dsi->base + idx.idx); | |
3de7a1dc TV |
416 | } |
417 | ||
a72b64b9 AT |
418 | static inline u32 dsi_read_reg(struct platform_device *dsidev, |
419 | const struct dsi_reg idx) | |
3de7a1dc | 420 | { |
f1da39d9 AT |
421 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
422 | ||
423 | return __raw_readl(dsi->base + idx.idx); | |
3de7a1dc TV |
424 | } |
425 | ||
1ffefe75 | 426 | void dsi_bus_lock(struct omap_dss_device *dssdev) |
3de7a1dc | 427 | { |
f1da39d9 AT |
428 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
429 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
430 | ||
431 | down(&dsi->bus_lock); | |
3de7a1dc TV |
432 | } |
433 | EXPORT_SYMBOL(dsi_bus_lock); | |
434 | ||
1ffefe75 | 435 | void dsi_bus_unlock(struct omap_dss_device *dssdev) |
3de7a1dc | 436 | { |
f1da39d9 AT |
437 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
438 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
439 | ||
440 | up(&dsi->bus_lock); | |
3de7a1dc TV |
441 | } |
442 | EXPORT_SYMBOL(dsi_bus_unlock); | |
443 | ||
a72b64b9 | 444 | static bool dsi_bus_is_locked(struct platform_device *dsidev) |
4f765023 | 445 | { |
f1da39d9 AT |
446 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
447 | ||
448 | return dsi->bus_lock.count == 0; | |
4f765023 TV |
449 | } |
450 | ||
f36a06e7 TV |
451 | static void dsi_completion_handler(void *data, u32 mask) |
452 | { | |
453 | complete((struct completion *)data); | |
454 | } | |
455 | ||
a72b64b9 AT |
456 | static inline int wait_for_bit_change(struct platform_device *dsidev, |
457 | const struct dsi_reg idx, int bitnum, int value) | |
3de7a1dc | 458 | { |
3b98409e TV |
459 | unsigned long timeout; |
460 | ktime_t wait; | |
461 | int t; | |
3de7a1dc | 462 | |
3b98409e TV |
463 | /* first busyloop to see if the bit changes right away */ |
464 | t = 100; | |
465 | while (t-- > 0) { | |
466 | if (REG_GET(dsidev, idx, bitnum, bitnum) == value) | |
467 | return value; | |
3de7a1dc TV |
468 | } |
469 | ||
3b98409e TV |
470 | /* then loop for 500ms, sleeping for 1ms in between */ |
471 | timeout = jiffies + msecs_to_jiffies(500); | |
472 | while (time_before(jiffies, timeout)) { | |
473 | if (REG_GET(dsidev, idx, bitnum, bitnum) == value) | |
474 | return value; | |
3de7a1dc | 475 | |
3b98409e TV |
476 | wait = ns_to_ktime(1000 * 1000); |
477 | set_current_state(TASK_UNINTERRUPTIBLE); | |
478 | schedule_hrtimeout(&wait, HRTIMER_MODE_REL); | |
3de7a1dc TV |
479 | } |
480 | ||
3b98409e | 481 | return !value; |
3de7a1dc TV |
482 | } |
483 | ||
a3b3cc2b AT |
484 | u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt) |
485 | { | |
486 | switch (fmt) { | |
487 | case OMAP_DSS_DSI_FMT_RGB888: | |
488 | case OMAP_DSS_DSI_FMT_RGB666: | |
489 | return 24; | |
490 | case OMAP_DSS_DSI_FMT_RGB666_PACKED: | |
491 | return 18; | |
492 | case OMAP_DSS_DSI_FMT_RGB565: | |
493 | return 16; | |
494 | default: | |
495 | BUG(); | |
c6eee968 | 496 | return 0; |
a3b3cc2b AT |
497 | } |
498 | } | |
499 | ||
3de7a1dc | 500 | #ifdef DEBUG |
a72b64b9 | 501 | static void dsi_perf_mark_setup(struct platform_device *dsidev) |
3de7a1dc | 502 | { |
f1da39d9 AT |
503 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
504 | dsi->perf_setup_time = ktime_get(); | |
3de7a1dc TV |
505 | } |
506 | ||
a72b64b9 | 507 | static void dsi_perf_mark_start(struct platform_device *dsidev) |
3de7a1dc | 508 | { |
f1da39d9 AT |
509 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
510 | dsi->perf_start_time = ktime_get(); | |
3de7a1dc TV |
511 | } |
512 | ||
a72b64b9 | 513 | static void dsi_perf_show(struct platform_device *dsidev, const char *name) |
3de7a1dc | 514 | { |
f1da39d9 | 515 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
516 | ktime_t t, setup_time, trans_time; |
517 | u32 total_bytes; | |
518 | u32 setup_us, trans_us, total_us; | |
519 | ||
520 | if (!dsi_perf) | |
521 | return; | |
522 | ||
3de7a1dc TV |
523 | t = ktime_get(); |
524 | ||
f1da39d9 | 525 | setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time); |
3de7a1dc TV |
526 | setup_us = (u32)ktime_to_us(setup_time); |
527 | if (setup_us == 0) | |
528 | setup_us = 1; | |
529 | ||
f1da39d9 | 530 | trans_time = ktime_sub(t, dsi->perf_start_time); |
3de7a1dc TV |
531 | trans_us = (u32)ktime_to_us(trans_time); |
532 | if (trans_us == 0) | |
533 | trans_us = 1; | |
534 | ||
535 | total_us = setup_us + trans_us; | |
536 | ||
5476e74a | 537 | total_bytes = dsi->update_bytes; |
3de7a1dc | 538 | |
1bbb275e TV |
539 | printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), " |
540 | "%u bytes, %u kbytes/sec\n", | |
541 | name, | |
542 | setup_us, | |
543 | trans_us, | |
544 | total_us, | |
545 | 1000*1000 / total_us, | |
546 | total_bytes, | |
547 | total_bytes * 1000 / total_us); | |
3de7a1dc TV |
548 | } |
549 | #else | |
4a9a5e39 TV |
550 | static inline void dsi_perf_mark_setup(struct platform_device *dsidev) |
551 | { | |
552 | } | |
553 | ||
554 | static inline void dsi_perf_mark_start(struct platform_device *dsidev) | |
555 | { | |
556 | } | |
557 | ||
558 | static inline void dsi_perf_show(struct platform_device *dsidev, | |
559 | const char *name) | |
560 | { | |
561 | } | |
3de7a1dc TV |
562 | #endif |
563 | ||
f30be7d3 CM |
564 | static int verbose_irq; |
565 | ||
3de7a1dc TV |
566 | static void print_irq_status(u32 status) |
567 | { | |
d80d499e TV |
568 | if (status == 0) |
569 | return; | |
570 | ||
f30be7d3 | 571 | if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0) |
3de7a1dc | 572 | return; |
3de7a1dc | 573 | |
f30be7d3 CM |
574 | #define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : "" |
575 | ||
576 | pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", | |
577 | status, | |
578 | verbose_irq ? PIS(VC0) : "", | |
579 | verbose_irq ? PIS(VC1) : "", | |
580 | verbose_irq ? PIS(VC2) : "", | |
581 | verbose_irq ? PIS(VC3) : "", | |
582 | PIS(WAKEUP), | |
583 | PIS(RESYNC), | |
584 | PIS(PLL_LOCK), | |
585 | PIS(PLL_UNLOCK), | |
586 | PIS(PLL_RECALL), | |
587 | PIS(COMPLEXIO_ERR), | |
588 | PIS(HS_TX_TIMEOUT), | |
589 | PIS(LP_RX_TIMEOUT), | |
590 | PIS(TE_TRIGGER), | |
591 | PIS(ACK_TRIGGER), | |
592 | PIS(SYNC_LOST), | |
593 | PIS(LDO_POWER_GOOD), | |
594 | PIS(TA_TIMEOUT)); | |
595 | #undef PIS | |
3de7a1dc TV |
596 | } |
597 | ||
598 | static void print_irq_status_vc(int channel, u32 status) | |
599 | { | |
d80d499e TV |
600 | if (status == 0) |
601 | return; | |
602 | ||
f30be7d3 | 603 | if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0) |
3de7a1dc | 604 | return; |
f30be7d3 CM |
605 | |
606 | #define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : "" | |
607 | ||
608 | pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n", | |
609 | channel, | |
610 | status, | |
611 | PIS(CS), | |
612 | PIS(ECC_CORR), | |
613 | PIS(ECC_NO_CORR), | |
614 | verbose_irq ? PIS(PACKET_SENT) : "", | |
615 | PIS(BTA), | |
616 | PIS(FIFO_TX_OVF), | |
617 | PIS(FIFO_RX_OVF), | |
618 | PIS(FIFO_TX_UDF), | |
619 | PIS(PP_BUSY_CHANGE)); | |
3de7a1dc | 620 | #undef PIS |
3de7a1dc TV |
621 | } |
622 | ||
623 | static void print_irq_status_cio(u32 status) | |
624 | { | |
d80d499e TV |
625 | if (status == 0) |
626 | return; | |
627 | ||
f30be7d3 CM |
628 | #define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : "" |
629 | ||
630 | 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", | |
631 | status, | |
632 | PIS(ERRSYNCESC1), | |
633 | PIS(ERRSYNCESC2), | |
634 | PIS(ERRSYNCESC3), | |
635 | PIS(ERRESC1), | |
636 | PIS(ERRESC2), | |
637 | PIS(ERRESC3), | |
638 | PIS(ERRCONTROL1), | |
639 | PIS(ERRCONTROL2), | |
640 | PIS(ERRCONTROL3), | |
641 | PIS(STATEULPS1), | |
642 | PIS(STATEULPS2), | |
643 | PIS(STATEULPS3), | |
644 | PIS(ERRCONTENTIONLP0_1), | |
645 | PIS(ERRCONTENTIONLP1_1), | |
646 | PIS(ERRCONTENTIONLP0_2), | |
647 | PIS(ERRCONTENTIONLP1_2), | |
648 | PIS(ERRCONTENTIONLP0_3), | |
649 | PIS(ERRCONTENTIONLP1_3), | |
650 | PIS(ULPSACTIVENOT_ALL0), | |
651 | PIS(ULPSACTIVENOT_ALL1)); | |
3de7a1dc | 652 | #undef PIS |
3de7a1dc TV |
653 | } |
654 | ||
69b281a6 | 655 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
a72b64b9 AT |
656 | static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus, |
657 | u32 *vcstatus, u32 ciostatus) | |
3de7a1dc | 658 | { |
f1da39d9 | 659 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
660 | int i; |
661 | ||
f1da39d9 | 662 | spin_lock(&dsi->irq_stats_lock); |
69b281a6 | 663 | |
f1da39d9 AT |
664 | dsi->irq_stats.irq_count++; |
665 | dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs); | |
69b281a6 TV |
666 | |
667 | for (i = 0; i < 4; ++i) | |
f1da39d9 | 668 | dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]); |
69b281a6 | 669 | |
f1da39d9 | 670 | dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs); |
69b281a6 | 671 | |
f1da39d9 | 672 | spin_unlock(&dsi->irq_stats_lock); |
69b281a6 TV |
673 | } |
674 | #else | |
a72b64b9 | 675 | #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus) |
dfc0fd8d TV |
676 | #endif |
677 | ||
69b281a6 TV |
678 | static int debug_irq; |
679 | ||
a72b64b9 AT |
680 | static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus, |
681 | u32 *vcstatus, u32 ciostatus) | |
69b281a6 | 682 | { |
f1da39d9 | 683 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
69b281a6 TV |
684 | int i; |
685 | ||
3de7a1dc TV |
686 | if (irqstatus & DSI_IRQ_ERROR_MASK) { |
687 | DSSERR("DSI error, irqstatus %x\n", irqstatus); | |
688 | print_irq_status(irqstatus); | |
f1da39d9 AT |
689 | spin_lock(&dsi->errors_lock); |
690 | dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK; | |
691 | spin_unlock(&dsi->errors_lock); | |
3de7a1dc TV |
692 | } else if (debug_irq) { |
693 | print_irq_status(irqstatus); | |
694 | } | |
695 | ||
3de7a1dc | 696 | for (i = 0; i < 4; ++i) { |
69b281a6 TV |
697 | if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) { |
698 | DSSERR("DSI VC(%d) error, vc irqstatus %x\n", | |
699 | i, vcstatus[i]); | |
700 | print_irq_status_vc(i, vcstatus[i]); | |
701 | } else if (debug_irq) { | |
702 | print_irq_status_vc(i, vcstatus[i]); | |
703 | } | |
704 | } | |
3de7a1dc | 705 | |
69b281a6 TV |
706 | if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) { |
707 | DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus); | |
708 | print_irq_status_cio(ciostatus); | |
709 | } else if (debug_irq) { | |
710 | print_irq_status_cio(ciostatus); | |
711 | } | |
712 | } | |
3de7a1dc | 713 | |
4ae2dddd TV |
714 | static void dsi_call_isrs(struct dsi_isr_data *isr_array, |
715 | unsigned isr_array_size, u32 irqstatus) | |
716 | { | |
717 | struct dsi_isr_data *isr_data; | |
718 | int i; | |
719 | ||
720 | for (i = 0; i < isr_array_size; i++) { | |
721 | isr_data = &isr_array[i]; | |
722 | if (isr_data->isr && isr_data->mask & irqstatus) | |
723 | isr_data->isr(isr_data->arg, irqstatus); | |
724 | } | |
725 | } | |
726 | ||
727 | static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables, | |
728 | u32 irqstatus, u32 *vcstatus, u32 ciostatus) | |
729 | { | |
730 | int i; | |
731 | ||
732 | dsi_call_isrs(isr_tables->isr_table, | |
733 | ARRAY_SIZE(isr_tables->isr_table), | |
734 | irqstatus); | |
735 | ||
736 | for (i = 0; i < 4; ++i) { | |
737 | if (vcstatus[i] == 0) | |
738 | continue; | |
739 | dsi_call_isrs(isr_tables->isr_table_vc[i], | |
740 | ARRAY_SIZE(isr_tables->isr_table_vc[i]), | |
741 | vcstatus[i]); | |
742 | } | |
743 | ||
744 | if (ciostatus != 0) | |
745 | dsi_call_isrs(isr_tables->isr_table_cio, | |
746 | ARRAY_SIZE(isr_tables->isr_table_cio), | |
747 | ciostatus); | |
748 | } | |
749 | ||
69b281a6 TV |
750 | static irqreturn_t omap_dsi_irq_handler(int irq, void *arg) |
751 | { | |
a72b64b9 | 752 | struct platform_device *dsidev; |
f1da39d9 | 753 | struct dsi_data *dsi; |
69b281a6 TV |
754 | u32 irqstatus, vcstatus[4], ciostatus; |
755 | int i; | |
dfc0fd8d | 756 | |
a72b64b9 | 757 | dsidev = (struct platform_device *) arg; |
f1da39d9 | 758 | dsi = dsi_get_dsidrv_data(dsidev); |
a72b64b9 | 759 | |
f1da39d9 | 760 | spin_lock(&dsi->irq_lock); |
4ae2dddd | 761 | |
a72b64b9 | 762 | irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS); |
3de7a1dc | 763 | |
69b281a6 | 764 | /* IRQ is not for us */ |
4ae2dddd | 765 | if (!irqstatus) { |
f1da39d9 | 766 | spin_unlock(&dsi->irq_lock); |
69b281a6 | 767 | return IRQ_NONE; |
4ae2dddd | 768 | } |
ab83b14c | 769 | |
a72b64b9 | 770 | dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK); |
69b281a6 | 771 | /* flush posted write */ |
a72b64b9 | 772 | dsi_read_reg(dsidev, DSI_IRQSTATUS); |
69b281a6 TV |
773 | |
774 | for (i = 0; i < 4; ++i) { | |
775 | if ((irqstatus & (1 << i)) == 0) { | |
776 | vcstatus[i] = 0; | |
777 | continue; | |
3de7a1dc TV |
778 | } |
779 | ||
a72b64b9 | 780 | vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
69b281a6 | 781 | |
a72b64b9 | 782 | dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]); |
3de7a1dc | 783 | /* flush posted write */ |
a72b64b9 | 784 | dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
3de7a1dc TV |
785 | } |
786 | ||
787 | if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) { | |
a72b64b9 | 788 | ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
3de7a1dc | 789 | |
a72b64b9 | 790 | dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus); |
3de7a1dc | 791 | /* flush posted write */ |
a72b64b9 | 792 | dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
69b281a6 TV |
793 | } else { |
794 | ciostatus = 0; | |
795 | } | |
3de7a1dc | 796 | |
69b281a6 TV |
797 | #ifdef DSI_CATCH_MISSING_TE |
798 | if (irqstatus & DSI_IRQ_TE_TRIGGER) | |
f1da39d9 | 799 | del_timer(&dsi->te_timer); |
69b281a6 TV |
800 | #endif |
801 | ||
4ae2dddd TV |
802 | /* make a copy and unlock, so that isrs can unregister |
803 | * themselves */ | |
f1da39d9 AT |
804 | memcpy(&dsi->isr_tables_copy, &dsi->isr_tables, |
805 | sizeof(dsi->isr_tables)); | |
4ae2dddd | 806 | |
f1da39d9 | 807 | spin_unlock(&dsi->irq_lock); |
4ae2dddd | 808 | |
f1da39d9 | 809 | dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus); |
4ae2dddd | 810 | |
a72b64b9 | 811 | dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus); |
69b281a6 | 812 | |
a72b64b9 | 813 | dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus); |
dfc0fd8d | 814 | |
affe360d | 815 | return IRQ_HANDLED; |
3de7a1dc TV |
816 | } |
817 | ||
f1da39d9 | 818 | /* dsi->irq_lock has to be locked by the caller */ |
a72b64b9 AT |
819 | static void _omap_dsi_configure_irqs(struct platform_device *dsidev, |
820 | struct dsi_isr_data *isr_array, | |
4ae2dddd TV |
821 | unsigned isr_array_size, u32 default_mask, |
822 | const struct dsi_reg enable_reg, | |
823 | const struct dsi_reg status_reg) | |
3de7a1dc | 824 | { |
4ae2dddd TV |
825 | struct dsi_isr_data *isr_data; |
826 | u32 mask; | |
827 | u32 old_mask; | |
3de7a1dc TV |
828 | int i; |
829 | ||
4ae2dddd | 830 | mask = default_mask; |
3de7a1dc | 831 | |
4ae2dddd TV |
832 | for (i = 0; i < isr_array_size; i++) { |
833 | isr_data = &isr_array[i]; | |
3de7a1dc | 834 | |
4ae2dddd TV |
835 | if (isr_data->isr == NULL) |
836 | continue; | |
837 | ||
838 | mask |= isr_data->mask; | |
3de7a1dc TV |
839 | } |
840 | ||
a72b64b9 | 841 | old_mask = dsi_read_reg(dsidev, enable_reg); |
4ae2dddd | 842 | /* clear the irqstatus for newly enabled irqs */ |
a72b64b9 AT |
843 | dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask); |
844 | dsi_write_reg(dsidev, enable_reg, mask); | |
4ae2dddd TV |
845 | |
846 | /* flush posted writes */ | |
a72b64b9 AT |
847 | dsi_read_reg(dsidev, enable_reg); |
848 | dsi_read_reg(dsidev, status_reg); | |
4ae2dddd | 849 | } |
3de7a1dc | 850 | |
f1da39d9 | 851 | /* dsi->irq_lock has to be locked by the caller */ |
a72b64b9 | 852 | static void _omap_dsi_set_irqs(struct platform_device *dsidev) |
4ae2dddd | 853 | { |
f1da39d9 | 854 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd | 855 | u32 mask = DSI_IRQ_ERROR_MASK; |
3de7a1dc | 856 | #ifdef DSI_CATCH_MISSING_TE |
4ae2dddd | 857 | mask |= DSI_IRQ_TE_TRIGGER; |
3de7a1dc | 858 | #endif |
f1da39d9 AT |
859 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table, |
860 | ARRAY_SIZE(dsi->isr_tables.isr_table), mask, | |
4ae2dddd TV |
861 | DSI_IRQENABLE, DSI_IRQSTATUS); |
862 | } | |
3de7a1dc | 863 | |
f1da39d9 | 864 | /* dsi->irq_lock has to be locked by the caller */ |
a72b64b9 | 865 | static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc) |
4ae2dddd | 866 | { |
f1da39d9 AT |
867 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
868 | ||
869 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc], | |
870 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]), | |
4ae2dddd TV |
871 | DSI_VC_IRQ_ERROR_MASK, |
872 | DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc)); | |
873 | } | |
874 | ||
f1da39d9 | 875 | /* dsi->irq_lock has to be locked by the caller */ |
a72b64b9 | 876 | static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev) |
4ae2dddd | 877 | { |
f1da39d9 AT |
878 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
879 | ||
880 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio, | |
881 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio), | |
4ae2dddd TV |
882 | DSI_CIO_IRQ_ERROR_MASK, |
883 | DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS); | |
884 | } | |
885 | ||
a72b64b9 | 886 | static void _dsi_initialize_irq(struct platform_device *dsidev) |
4ae2dddd | 887 | { |
f1da39d9 | 888 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd TV |
889 | unsigned long flags; |
890 | int vc; | |
891 | ||
f1da39d9 | 892 | spin_lock_irqsave(&dsi->irq_lock, flags); |
4ae2dddd | 893 | |
f1da39d9 | 894 | memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables)); |
4ae2dddd | 895 | |
a72b64b9 | 896 | _omap_dsi_set_irqs(dsidev); |
4ae2dddd | 897 | for (vc = 0; vc < 4; ++vc) |
a72b64b9 AT |
898 | _omap_dsi_set_irqs_vc(dsidev, vc); |
899 | _omap_dsi_set_irqs_cio(dsidev); | |
4ae2dddd | 900 | |
f1da39d9 | 901 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
4ae2dddd | 902 | } |
3de7a1dc | 903 | |
4ae2dddd TV |
904 | static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask, |
905 | struct dsi_isr_data *isr_array, unsigned isr_array_size) | |
906 | { | |
907 | struct dsi_isr_data *isr_data; | |
908 | int free_idx; | |
909 | int i; | |
910 | ||
911 | BUG_ON(isr == NULL); | |
912 | ||
913 | /* check for duplicate entry and find a free slot */ | |
914 | free_idx = -1; | |
915 | for (i = 0; i < isr_array_size; i++) { | |
916 | isr_data = &isr_array[i]; | |
917 | ||
918 | if (isr_data->isr == isr && isr_data->arg == arg && | |
919 | isr_data->mask == mask) { | |
920 | return -EINVAL; | |
921 | } | |
922 | ||
923 | if (isr_data->isr == NULL && free_idx == -1) | |
924 | free_idx = i; | |
925 | } | |
926 | ||
927 | if (free_idx == -1) | |
928 | return -EBUSY; | |
929 | ||
930 | isr_data = &isr_array[free_idx]; | |
931 | isr_data->isr = isr; | |
932 | isr_data->arg = arg; | |
933 | isr_data->mask = mask; | |
934 | ||
935 | return 0; | |
936 | } | |
937 | ||
938 | static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask, | |
939 | struct dsi_isr_data *isr_array, unsigned isr_array_size) | |
940 | { | |
941 | struct dsi_isr_data *isr_data; | |
942 | int i; | |
943 | ||
944 | for (i = 0; i < isr_array_size; i++) { | |
945 | isr_data = &isr_array[i]; | |
946 | if (isr_data->isr != isr || isr_data->arg != arg || | |
947 | isr_data->mask != mask) | |
948 | continue; | |
949 | ||
950 | isr_data->isr = NULL; | |
951 | isr_data->arg = NULL; | |
952 | isr_data->mask = 0; | |
953 | ||
954 | return 0; | |
955 | } | |
956 | ||
957 | return -EINVAL; | |
958 | } | |
959 | ||
a72b64b9 AT |
960 | static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr, |
961 | void *arg, u32 mask) | |
4ae2dddd | 962 | { |
f1da39d9 | 963 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd TV |
964 | unsigned long flags; |
965 | int r; | |
966 | ||
f1da39d9 | 967 | spin_lock_irqsave(&dsi->irq_lock, flags); |
4ae2dddd | 968 | |
f1da39d9 AT |
969 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
970 | ARRAY_SIZE(dsi->isr_tables.isr_table)); | |
4ae2dddd TV |
971 | |
972 | if (r == 0) | |
a72b64b9 | 973 | _omap_dsi_set_irqs(dsidev); |
4ae2dddd | 974 | |
f1da39d9 | 975 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
4ae2dddd TV |
976 | |
977 | return r; | |
978 | } | |
979 | ||
a72b64b9 AT |
980 | static int dsi_unregister_isr(struct platform_device *dsidev, |
981 | omap_dsi_isr_t isr, void *arg, u32 mask) | |
4ae2dddd | 982 | { |
f1da39d9 | 983 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd TV |
984 | unsigned long flags; |
985 | int r; | |
986 | ||
f1da39d9 | 987 | spin_lock_irqsave(&dsi->irq_lock, flags); |
4ae2dddd | 988 | |
f1da39d9 AT |
989 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
990 | ARRAY_SIZE(dsi->isr_tables.isr_table)); | |
4ae2dddd TV |
991 | |
992 | if (r == 0) | |
a72b64b9 | 993 | _omap_dsi_set_irqs(dsidev); |
4ae2dddd | 994 | |
f1da39d9 | 995 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
4ae2dddd TV |
996 | |
997 | return r; | |
998 | } | |
999 | ||
a72b64b9 AT |
1000 | static int dsi_register_isr_vc(struct platform_device *dsidev, int channel, |
1001 | omap_dsi_isr_t isr, void *arg, u32 mask) | |
4ae2dddd | 1002 | { |
f1da39d9 | 1003 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd TV |
1004 | unsigned long flags; |
1005 | int r; | |
1006 | ||
f1da39d9 | 1007 | spin_lock_irqsave(&dsi->irq_lock, flags); |
4ae2dddd TV |
1008 | |
1009 | r = _dsi_register_isr(isr, arg, mask, | |
f1da39d9 AT |
1010 | dsi->isr_tables.isr_table_vc[channel], |
1011 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); | |
4ae2dddd TV |
1012 | |
1013 | if (r == 0) | |
a72b64b9 | 1014 | _omap_dsi_set_irqs_vc(dsidev, channel); |
4ae2dddd | 1015 | |
f1da39d9 | 1016 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
4ae2dddd TV |
1017 | |
1018 | return r; | |
1019 | } | |
1020 | ||
a72b64b9 AT |
1021 | static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel, |
1022 | omap_dsi_isr_t isr, void *arg, u32 mask) | |
4ae2dddd | 1023 | { |
f1da39d9 | 1024 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd TV |
1025 | unsigned long flags; |
1026 | int r; | |
1027 | ||
f1da39d9 | 1028 | spin_lock_irqsave(&dsi->irq_lock, flags); |
4ae2dddd TV |
1029 | |
1030 | r = _dsi_unregister_isr(isr, arg, mask, | |
f1da39d9 AT |
1031 | dsi->isr_tables.isr_table_vc[channel], |
1032 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); | |
4ae2dddd TV |
1033 | |
1034 | if (r == 0) | |
a72b64b9 | 1035 | _omap_dsi_set_irqs_vc(dsidev, channel); |
4ae2dddd | 1036 | |
f1da39d9 | 1037 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
4ae2dddd TV |
1038 | |
1039 | return r; | |
1040 | } | |
1041 | ||
a72b64b9 AT |
1042 | static int dsi_register_isr_cio(struct platform_device *dsidev, |
1043 | omap_dsi_isr_t isr, void *arg, u32 mask) | |
4ae2dddd | 1044 | { |
f1da39d9 | 1045 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd TV |
1046 | unsigned long flags; |
1047 | int r; | |
1048 | ||
f1da39d9 | 1049 | spin_lock_irqsave(&dsi->irq_lock, flags); |
4ae2dddd | 1050 | |
f1da39d9 AT |
1051 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
1052 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); | |
4ae2dddd TV |
1053 | |
1054 | if (r == 0) | |
a72b64b9 | 1055 | _omap_dsi_set_irqs_cio(dsidev); |
4ae2dddd | 1056 | |
f1da39d9 | 1057 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
4ae2dddd TV |
1058 | |
1059 | return r; | |
1060 | } | |
1061 | ||
a72b64b9 AT |
1062 | static int dsi_unregister_isr_cio(struct platform_device *dsidev, |
1063 | omap_dsi_isr_t isr, void *arg, u32 mask) | |
4ae2dddd | 1064 | { |
f1da39d9 | 1065 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4ae2dddd TV |
1066 | unsigned long flags; |
1067 | int r; | |
1068 | ||
f1da39d9 | 1069 | spin_lock_irqsave(&dsi->irq_lock, flags); |
4ae2dddd | 1070 | |
f1da39d9 AT |
1071 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
1072 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); | |
4ae2dddd TV |
1073 | |
1074 | if (r == 0) | |
a72b64b9 | 1075 | _omap_dsi_set_irqs_cio(dsidev); |
4ae2dddd | 1076 | |
f1da39d9 | 1077 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
4ae2dddd TV |
1078 | |
1079 | return r; | |
3de7a1dc TV |
1080 | } |
1081 | ||
a72b64b9 | 1082 | static u32 dsi_get_errors(struct platform_device *dsidev) |
3de7a1dc | 1083 | { |
f1da39d9 | 1084 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
1085 | unsigned long flags; |
1086 | u32 e; | |
f1da39d9 AT |
1087 | spin_lock_irqsave(&dsi->errors_lock, flags); |
1088 | e = dsi->errors; | |
1089 | dsi->errors = 0; | |
1090 | spin_unlock_irqrestore(&dsi->errors_lock, flags); | |
3de7a1dc TV |
1091 | return e; |
1092 | } | |
1093 | ||
4fbafaf3 | 1094 | int dsi_runtime_get(struct platform_device *dsidev) |
3de7a1dc | 1095 | { |
4fbafaf3 TV |
1096 | int r; |
1097 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1098 | ||
1099 | DSSDBG("dsi_runtime_get\n"); | |
1100 | ||
1101 | r = pm_runtime_get_sync(&dsi->pdev->dev); | |
1102 | WARN_ON(r < 0); | |
1103 | return r < 0 ? r : 0; | |
1104 | } | |
1105 | ||
1106 | void dsi_runtime_put(struct platform_device *dsidev) | |
1107 | { | |
1108 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1109 | int r; | |
1110 | ||
1111 | DSSDBG("dsi_runtime_put\n"); | |
1112 | ||
0eaf9f52 | 1113 | r = pm_runtime_put_sync(&dsi->pdev->dev); |
5be3aebd | 1114 | WARN_ON(r < 0 && r != -ENOSYS); |
3de7a1dc TV |
1115 | } |
1116 | ||
b2541c40 TV |
1117 | static int dsi_regulator_init(struct platform_device *dsidev) |
1118 | { | |
1119 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1120 | struct regulator *vdds_dsi; | |
1121 | ||
1122 | if (dsi->vdds_dsi_reg != NULL) | |
1123 | return 0; | |
1124 | ||
1125 | vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "vdds_dsi"); | |
1126 | ||
1127 | /* DT HACK: try VCXIO to make omapdss work for o4 sdp/panda */ | |
1128 | if (IS_ERR(vdds_dsi)) | |
1129 | vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "VCXIO"); | |
1130 | ||
1131 | if (IS_ERR(vdds_dsi)) { | |
1132 | DSSERR("can't get VDDS_DSI regulator\n"); | |
1133 | return PTR_ERR(vdds_dsi); | |
1134 | } | |
1135 | ||
1136 | dsi->vdds_dsi_reg = vdds_dsi; | |
1137 | ||
1138 | return 0; | |
1139 | } | |
1140 | ||
3de7a1dc | 1141 | /* source clock for DSI PLL. this could also be PCLKFREE */ |
a72b64b9 AT |
1142 | static inline void dsi_enable_pll_clock(struct platform_device *dsidev, |
1143 | bool enable) | |
3de7a1dc | 1144 | { |
f1da39d9 AT |
1145 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1146 | ||
3de7a1dc | 1147 | if (enable) |
f11766d1 | 1148 | clk_prepare_enable(dsi->sys_clk); |
3de7a1dc | 1149 | else |
f11766d1 | 1150 | clk_disable_unprepare(dsi->sys_clk); |
3de7a1dc | 1151 | |
f1da39d9 | 1152 | if (enable && dsi->pll_locked) { |
a72b64b9 | 1153 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) |
3de7a1dc TV |
1154 | DSSERR("cannot lock PLL when enabling clocks\n"); |
1155 | } | |
1156 | } | |
1157 | ||
a72b64b9 | 1158 | static void _dsi_print_reset_status(struct platform_device *dsidev) |
3de7a1dc TV |
1159 | { |
1160 | u32 l; | |
c335cbf9 | 1161 | int b0, b1, b2; |
3de7a1dc | 1162 | |
3de7a1dc TV |
1163 | /* A dummy read using the SCP interface to any DSIPHY register is |
1164 | * required after DSIPHY reset to complete the reset of the DSI complex | |
1165 | * I/O. */ | |
a72b64b9 | 1166 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
3de7a1dc | 1167 | |
c335cbf9 TV |
1168 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) { |
1169 | b0 = 28; | |
1170 | b1 = 27; | |
1171 | b2 = 26; | |
1172 | } else { | |
1173 | b0 = 24; | |
1174 | b1 = 25; | |
1175 | b2 = 26; | |
1176 | } | |
1177 | ||
f30be7d3 CM |
1178 | #define DSI_FLD_GET(fld, start, end)\ |
1179 | FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end) | |
1180 | ||
1181 | pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n", | |
1182 | DSI_FLD_GET(PLL_STATUS, 0, 0), | |
1183 | DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29), | |
1184 | DSI_FLD_GET(DSIPHY_CFG5, b0, b0), | |
1185 | DSI_FLD_GET(DSIPHY_CFG5, b1, b1), | |
1186 | DSI_FLD_GET(DSIPHY_CFG5, b2, b2), | |
1187 | DSI_FLD_GET(DSIPHY_CFG5, 29, 29), | |
1188 | DSI_FLD_GET(DSIPHY_CFG5, 30, 30), | |
1189 | DSI_FLD_GET(DSIPHY_CFG5, 31, 31)); | |
1190 | ||
1191 | #undef DSI_FLD_GET | |
3de7a1dc | 1192 | } |
3de7a1dc | 1193 | |
a72b64b9 | 1194 | static inline int dsi_if_enable(struct platform_device *dsidev, bool enable) |
3de7a1dc TV |
1195 | { |
1196 | DSSDBG("dsi_if_enable(%d)\n", enable); | |
1197 | ||
1198 | enable = enable ? 1 : 0; | |
a72b64b9 | 1199 | REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */ |
3de7a1dc | 1200 | |
a72b64b9 | 1201 | if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) { |
3de7a1dc TV |
1202 | DSSERR("Failed to set dsi_if_enable to %d\n", enable); |
1203 | return -EIO; | |
1204 | } | |
1205 | ||
1206 | return 0; | |
1207 | } | |
1208 | ||
a72b64b9 | 1209 | unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev) |
3de7a1dc | 1210 | { |
f1da39d9 AT |
1211 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1212 | ||
1213 | return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk; | |
3de7a1dc TV |
1214 | } |
1215 | ||
a72b64b9 | 1216 | static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev) |
3de7a1dc | 1217 | { |
f1da39d9 AT |
1218 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1219 | ||
1220 | return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk; | |
3de7a1dc TV |
1221 | } |
1222 | ||
a72b64b9 | 1223 | static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev) |
3de7a1dc | 1224 | { |
f1da39d9 AT |
1225 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1226 | ||
1227 | return dsi->current_cinfo.clkin4ddr / 16; | |
3de7a1dc TV |
1228 | } |
1229 | ||
a72b64b9 | 1230 | static unsigned long dsi_fclk_rate(struct platform_device *dsidev) |
3de7a1dc TV |
1231 | { |
1232 | unsigned long r; | |
4fbafaf3 | 1233 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc | 1234 | |
11ee9606 | 1235 | if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) { |
1bb47835 | 1236 | /* DSI FCLK source is DSS_CLK_FCK */ |
4fbafaf3 | 1237 | r = clk_get_rate(dsi->dss_clk); |
3de7a1dc | 1238 | } else { |
1bb47835 | 1239 | /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */ |
a72b64b9 | 1240 | r = dsi_get_pll_hsdiv_dsi_rate(dsidev); |
3de7a1dc TV |
1241 | } |
1242 | ||
1243 | return r; | |
1244 | } | |
1245 | ||
f1e0001f TV |
1246 | static int dsi_lp_clock_calc(struct dsi_clock_info *cinfo, |
1247 | unsigned long lp_clk_min, unsigned long lp_clk_max) | |
1248 | { | |
1249 | unsigned long dsi_fclk = cinfo->dsi_pll_hsdiv_dsi_clk; | |
1250 | unsigned lp_clk_div; | |
1251 | unsigned long lp_clk; | |
1252 | ||
1253 | lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk_max * 2); | |
1254 | lp_clk = dsi_fclk / 2 / lp_clk_div; | |
1255 | ||
1256 | if (lp_clk < lp_clk_min || lp_clk > lp_clk_max) | |
1257 | return -EINVAL; | |
1258 | ||
1259 | cinfo->lp_clk_div = lp_clk_div; | |
1260 | cinfo->lp_clk = lp_clk; | |
1261 | ||
1262 | return 0; | |
1263 | } | |
1264 | ||
5761217a | 1265 | static int dsi_set_lp_clk_divisor(struct platform_device *dsidev) |
3de7a1dc | 1266 | { |
f1da39d9 | 1267 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
1268 | unsigned long dsi_fclk; |
1269 | unsigned lp_clk_div; | |
1270 | unsigned long lp_clk; | |
1271 | ||
a0d269ec | 1272 | lp_clk_div = dsi->user_dsi_cinfo.lp_clk_div; |
3de7a1dc | 1273 | |
f1da39d9 | 1274 | if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max) |
3de7a1dc TV |
1275 | return -EINVAL; |
1276 | ||
a72b64b9 | 1277 | dsi_fclk = dsi_fclk_rate(dsidev); |
3de7a1dc TV |
1278 | |
1279 | lp_clk = dsi_fclk / 2 / lp_clk_div; | |
1280 | ||
1281 | DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk); | |
f1da39d9 AT |
1282 | dsi->current_cinfo.lp_clk = lp_clk; |
1283 | dsi->current_cinfo.lp_clk_div = lp_clk_div; | |
3de7a1dc | 1284 | |
a72b64b9 AT |
1285 | /* LP_CLK_DIVISOR */ |
1286 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0); | |
3de7a1dc | 1287 | |
a72b64b9 AT |
1288 | /* LP_RX_SYNCHRO_ENABLE */ |
1289 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21); | |
3de7a1dc TV |
1290 | |
1291 | return 0; | |
1292 | } | |
1293 | ||
a72b64b9 | 1294 | static void dsi_enable_scp_clk(struct platform_device *dsidev) |
24c1ae41 | 1295 | { |
f1da39d9 AT |
1296 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1297 | ||
1298 | if (dsi->scp_clk_refcount++ == 0) | |
a72b64b9 | 1299 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */ |
24c1ae41 TV |
1300 | } |
1301 | ||
a72b64b9 | 1302 | static void dsi_disable_scp_clk(struct platform_device *dsidev) |
24c1ae41 | 1303 | { |
f1da39d9 AT |
1304 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1305 | ||
1306 | WARN_ON(dsi->scp_clk_refcount == 0); | |
1307 | if (--dsi->scp_clk_refcount == 0) | |
a72b64b9 | 1308 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */ |
24c1ae41 | 1309 | } |
3de7a1dc TV |
1310 | |
1311 | enum dsi_pll_power_state { | |
1312 | DSI_PLL_POWER_OFF = 0x0, | |
1313 | DSI_PLL_POWER_ON_HSCLK = 0x1, | |
1314 | DSI_PLL_POWER_ON_ALL = 0x2, | |
1315 | DSI_PLL_POWER_ON_DIV = 0x3, | |
1316 | }; | |
1317 | ||
a72b64b9 AT |
1318 | static int dsi_pll_power(struct platform_device *dsidev, |
1319 | enum dsi_pll_power_state state) | |
3de7a1dc TV |
1320 | { |
1321 | int t = 0; | |
1322 | ||
c94dfe05 TV |
1323 | /* DSI-PLL power command 0x3 is not working */ |
1324 | if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) && | |
1325 | state == DSI_PLL_POWER_ON_DIV) | |
1326 | state = DSI_PLL_POWER_ON_ALL; | |
1327 | ||
a72b64b9 AT |
1328 | /* PLL_PWR_CMD */ |
1329 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30); | |
3de7a1dc TV |
1330 | |
1331 | /* PLL_PWR_STATUS */ | |
a72b64b9 | 1332 | while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) { |
24be78b3 | 1333 | if (++t > 1000) { |
3de7a1dc TV |
1334 | DSSERR("Failed to set DSI PLL power mode to %d\n", |
1335 | state); | |
1336 | return -ENODEV; | |
1337 | } | |
24be78b3 | 1338 | udelay(1); |
3de7a1dc TV |
1339 | } |
1340 | ||
1341 | return 0; | |
1342 | } | |
1343 | ||
72658f07 TV |
1344 | unsigned long dsi_get_pll_clkin(struct platform_device *dsidev) |
1345 | { | |
1346 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1347 | return clk_get_rate(dsi->sys_clk); | |
1348 | } | |
1349 | ||
1350 | bool dsi_hsdiv_calc(struct platform_device *dsidev, unsigned long pll, | |
1351 | unsigned long out_min, dsi_hsdiv_calc_func func, void *data) | |
1352 | { | |
1353 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1354 | int regm, regm_start, regm_stop; | |
1355 | unsigned long out_max; | |
1356 | unsigned long out; | |
1357 | ||
1358 | out_min = out_min ? out_min : 1; | |
1359 | out_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); | |
1360 | ||
1361 | regm_start = max(DIV_ROUND_UP(pll, out_max), 1ul); | |
1362 | regm_stop = min(pll / out_min, dsi->regm_dispc_max); | |
1363 | ||
1364 | for (regm = regm_start; regm <= regm_stop; ++regm) { | |
1365 | out = pll / regm; | |
1366 | ||
1367 | if (func(regm, out, data)) | |
1368 | return true; | |
1369 | } | |
1370 | ||
1371 | return false; | |
1372 | } | |
1373 | ||
1374 | bool dsi_pll_calc(struct platform_device *dsidev, unsigned long clkin, | |
1375 | unsigned long pll_min, unsigned long pll_max, | |
1376 | dsi_pll_calc_func func, void *data) | |
1377 | { | |
1378 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1379 | int regn, regn_start, regn_stop; | |
1380 | int regm, regm_start, regm_stop; | |
1381 | unsigned long fint, pll; | |
1382 | const unsigned long pll_hw_max = 1800000000; | |
1383 | unsigned long fint_hw_min, fint_hw_max; | |
1384 | ||
1385 | fint_hw_min = dsi->fint_min; | |
1386 | fint_hw_max = dsi->fint_max; | |
1387 | ||
1388 | regn_start = max(DIV_ROUND_UP(clkin, fint_hw_max), 1ul); | |
1389 | regn_stop = min(clkin / fint_hw_min, dsi->regn_max); | |
1390 | ||
1391 | pll_max = pll_max ? pll_max : ULONG_MAX; | |
1392 | ||
1393 | for (regn = regn_start; regn <= regn_stop; ++regn) { | |
1394 | fint = clkin / regn; | |
1395 | ||
1396 | regm_start = max(DIV_ROUND_UP(DIV_ROUND_UP(pll_min, fint), 2), | |
1397 | 1ul); | |
1398 | regm_stop = min3(pll_max / fint / 2, | |
1399 | pll_hw_max / fint / 2, | |
1400 | dsi->regm_max); | |
1401 | ||
1402 | for (regm = regm_start; regm <= regm_stop; ++regm) { | |
1403 | pll = 2 * regm * fint; | |
1404 | ||
1405 | if (func(regn, regm, fint, pll, data)) | |
1406 | return true; | |
1407 | } | |
1408 | } | |
1409 | ||
1410 | return false; | |
1411 | } | |
1412 | ||
3de7a1dc | 1413 | /* calculate clock rates using dividers in cinfo */ |
b6e695ab | 1414 | static int dsi_calc_clock_rates(struct platform_device *dsidev, |
ff1b2cde | 1415 | struct dsi_clock_info *cinfo) |
3de7a1dc | 1416 | { |
f1da39d9 AT |
1417 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1418 | ||
1419 | if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max) | |
3de7a1dc TV |
1420 | return -EINVAL; |
1421 | ||
f1da39d9 | 1422 | if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max) |
3de7a1dc TV |
1423 | return -EINVAL; |
1424 | ||
f1da39d9 | 1425 | if (cinfo->regm_dispc > dsi->regm_dispc_max) |
3de7a1dc TV |
1426 | return -EINVAL; |
1427 | ||
f1da39d9 | 1428 | if (cinfo->regm_dsi > dsi->regm_dsi_max) |
3de7a1dc TV |
1429 | return -EINVAL; |
1430 | ||
b6e695ab TV |
1431 | cinfo->clkin = clk_get_rate(dsi->sys_clk); |
1432 | cinfo->fint = cinfo->clkin / cinfo->regn; | |
3de7a1dc | 1433 | |
f1da39d9 | 1434 | if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min) |
3de7a1dc TV |
1435 | return -EINVAL; |
1436 | ||
1437 | cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint; | |
1438 | ||
1439 | if (cinfo->clkin4ddr > 1800 * 1000 * 1000) | |
1440 | return -EINVAL; | |
1441 | ||
1bb47835 AT |
1442 | if (cinfo->regm_dispc > 0) |
1443 | cinfo->dsi_pll_hsdiv_dispc_clk = | |
1444 | cinfo->clkin4ddr / cinfo->regm_dispc; | |
3de7a1dc | 1445 | else |
1bb47835 | 1446 | cinfo->dsi_pll_hsdiv_dispc_clk = 0; |
3de7a1dc | 1447 | |
1bb47835 AT |
1448 | if (cinfo->regm_dsi > 0) |
1449 | cinfo->dsi_pll_hsdiv_dsi_clk = | |
1450 | cinfo->clkin4ddr / cinfo->regm_dsi; | |
3de7a1dc | 1451 | else |
1bb47835 | 1452 | cinfo->dsi_pll_hsdiv_dsi_clk = 0; |
3de7a1dc TV |
1453 | |
1454 | return 0; | |
1455 | } | |
1456 | ||
f1e0001f | 1457 | static void dsi_pll_calc_dsi_fck(struct dsi_clock_info *cinfo) |
d66b1581 TV |
1458 | { |
1459 | unsigned long max_dsi_fck; | |
1460 | ||
1461 | max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK); | |
1462 | ||
1463 | cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck); | |
1464 | cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi; | |
1465 | } | |
1466 | ||
a72b64b9 AT |
1467 | int dsi_pll_set_clock_div(struct platform_device *dsidev, |
1468 | struct dsi_clock_info *cinfo) | |
3de7a1dc | 1469 | { |
f1da39d9 | 1470 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
1471 | int r = 0; |
1472 | u32 l; | |
9613c02b | 1473 | int f = 0; |
49641116 TA |
1474 | u8 regn_start, regn_end, regm_start, regm_end; |
1475 | u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end; | |
3de7a1dc | 1476 | |
702d267e | 1477 | DSSDBG("DSI PLL clock config starts"); |
3de7a1dc | 1478 | |
b6e695ab | 1479 | dsi->current_cinfo.clkin = cinfo->clkin; |
f1da39d9 AT |
1480 | dsi->current_cinfo.fint = cinfo->fint; |
1481 | dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr; | |
1482 | dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk = | |
1bb47835 | 1483 | cinfo->dsi_pll_hsdiv_dispc_clk; |
f1da39d9 | 1484 | dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk = |
1bb47835 | 1485 | cinfo->dsi_pll_hsdiv_dsi_clk; |
3de7a1dc | 1486 | |
f1da39d9 AT |
1487 | dsi->current_cinfo.regn = cinfo->regn; |
1488 | dsi->current_cinfo.regm = cinfo->regm; | |
1489 | dsi->current_cinfo.regm_dispc = cinfo->regm_dispc; | |
1490 | dsi->current_cinfo.regm_dsi = cinfo->regm_dsi; | |
3de7a1dc TV |
1491 | |
1492 | DSSDBG("DSI Fint %ld\n", cinfo->fint); | |
1493 | ||
b6e695ab | 1494 | DSSDBG("clkin rate %ld\n", cinfo->clkin); |
3de7a1dc TV |
1495 | |
1496 | /* DSIPHY == CLKIN4DDR */ | |
b6e695ab | 1497 | DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n", |
3de7a1dc TV |
1498 | cinfo->regm, |
1499 | cinfo->regn, | |
1500 | cinfo->clkin, | |
3de7a1dc TV |
1501 | cinfo->clkin4ddr); |
1502 | ||
1503 | DSSDBG("Data rate on 1 DSI lane %ld Mbps\n", | |
1504 | cinfo->clkin4ddr / 1000 / 1000 / 2); | |
1505 | ||
1506 | DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4); | |
1507 | ||
1bb47835 | 1508 | DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc, |
89a35e51 AT |
1509 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
1510 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), | |
1bb47835 AT |
1511 | cinfo->dsi_pll_hsdiv_dispc_clk); |
1512 | DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi, | |
89a35e51 AT |
1513 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
1514 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), | |
1bb47835 | 1515 | cinfo->dsi_pll_hsdiv_dsi_clk); |
3de7a1dc | 1516 | |
49641116 TA |
1517 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, ®n_start, ®n_end); |
1518 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, ®m_start, ®m_end); | |
1519 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, ®m_dispc_start, | |
1520 | ®m_dispc_end); | |
1521 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, ®m_dsi_start, | |
1522 | ®m_dsi_end); | |
1523 | ||
a72b64b9 AT |
1524 | /* DSI_PLL_AUTOMODE = manual */ |
1525 | REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0); | |
3de7a1dc | 1526 | |
a72b64b9 | 1527 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1); |
3de7a1dc | 1528 | l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */ |
49641116 TA |
1529 | /* DSI_PLL_REGN */ |
1530 | l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end); | |
1531 | /* DSI_PLL_REGM */ | |
1532 | l = FLD_MOD(l, cinfo->regm, regm_start, regm_end); | |
1533 | /* DSI_CLOCK_DIV */ | |
1bb47835 | 1534 | l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0, |
49641116 TA |
1535 | regm_dispc_start, regm_dispc_end); |
1536 | /* DSIPROTO_CLOCK_DIV */ | |
1bb47835 | 1537 | l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0, |
49641116 | 1538 | regm_dsi_start, regm_dsi_end); |
a72b64b9 | 1539 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l); |
3de7a1dc | 1540 | |
f1da39d9 | 1541 | BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max); |
9613c02b | 1542 | |
f8ef3d69 TV |
1543 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
1544 | ||
9613c02b AT |
1545 | if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) { |
1546 | f = cinfo->fint < 1000000 ? 0x3 : | |
1547 | cinfo->fint < 1250000 ? 0x4 : | |
1548 | cinfo->fint < 1500000 ? 0x5 : | |
1549 | cinfo->fint < 1750000 ? 0x6 : | |
1550 | 0x7; | |
3de7a1dc | 1551 | |
9613c02b | 1552 | l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */ |
f8ef3d69 TV |
1553 | } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) { |
1554 | f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4; | |
1555 | ||
1556 | l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */ | |
1557 | } | |
1558 | ||
3de7a1dc TV |
1559 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ |
1560 | l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */ | |
1561 | l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */ | |
6d44610f TV |
1562 | if (dss_has_feature(FEAT_DSI_PLL_REFSEL)) |
1563 | l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */ | |
a72b64b9 | 1564 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
3de7a1dc | 1565 | |
a72b64b9 | 1566 | REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */ |
3de7a1dc | 1567 | |
a72b64b9 | 1568 | if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) { |
3de7a1dc TV |
1569 | DSSERR("dsi pll go bit not going down.\n"); |
1570 | r = -EIO; | |
1571 | goto err; | |
1572 | } | |
1573 | ||
a72b64b9 | 1574 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) { |
3de7a1dc TV |
1575 | DSSERR("cannot lock PLL\n"); |
1576 | r = -EIO; | |
1577 | goto err; | |
1578 | } | |
1579 | ||
f1da39d9 | 1580 | dsi->pll_locked = 1; |
3de7a1dc | 1581 | |
a72b64b9 | 1582 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
3de7a1dc TV |
1583 | l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */ |
1584 | l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */ | |
1585 | l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */ | |
1586 | l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */ | |
1587 | l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */ | |
1588 | l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */ | |
1589 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ | |
1590 | l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */ | |
1591 | l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */ | |
1592 | l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */ | |
1593 | l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */ | |
1594 | l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */ | |
1595 | l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */ | |
1596 | l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */ | |
a72b64b9 | 1597 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
3de7a1dc TV |
1598 | |
1599 | DSSDBG("PLL config done\n"); | |
1600 | err: | |
1601 | return r; | |
1602 | } | |
1603 | ||
a72b64b9 AT |
1604 | int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk, |
1605 | bool enable_hsdiv) | |
3de7a1dc | 1606 | { |
f1da39d9 | 1607 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
1608 | int r = 0; |
1609 | enum dsi_pll_power_state pwstate; | |
1610 | ||
1611 | DSSDBG("PLL init\n"); | |
1612 | ||
7a98786c TV |
1613 | /* |
1614 | * It seems that on many OMAPs we need to enable both to have a | |
1615 | * functional HSDivider. | |
1616 | */ | |
1617 | enable_hsclk = enable_hsdiv = true; | |
1618 | ||
b2541c40 TV |
1619 | r = dsi_regulator_init(dsidev); |
1620 | if (r) | |
1621 | return r; | |
f2988ab9 | 1622 | |
a72b64b9 | 1623 | dsi_enable_pll_clock(dsidev, 1); |
24c1ae41 TV |
1624 | /* |
1625 | * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4. | |
1626 | */ | |
a72b64b9 | 1627 | dsi_enable_scp_clk(dsidev); |
3de7a1dc | 1628 | |
f1da39d9 AT |
1629 | if (!dsi->vdds_dsi_enabled) { |
1630 | r = regulator_enable(dsi->vdds_dsi_reg); | |
2a89dc15 TV |
1631 | if (r) |
1632 | goto err0; | |
f1da39d9 | 1633 | dsi->vdds_dsi_enabled = true; |
2a89dc15 | 1634 | } |
3de7a1dc TV |
1635 | |
1636 | /* XXX PLL does not come out of reset without this... */ | |
1637 | dispc_pck_free_enable(1); | |
1638 | ||
a72b64b9 | 1639 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) { |
3de7a1dc TV |
1640 | DSSERR("PLL not coming out of reset.\n"); |
1641 | r = -ENODEV; | |
481dfa0e | 1642 | dispc_pck_free_enable(0); |
3de7a1dc TV |
1643 | goto err1; |
1644 | } | |
1645 | ||
1646 | /* XXX ... but if left on, we get problems when planes do not | |
1647 | * fill the whole display. No idea about this */ | |
1648 | dispc_pck_free_enable(0); | |
1649 | ||
1650 | if (enable_hsclk && enable_hsdiv) | |
1651 | pwstate = DSI_PLL_POWER_ON_ALL; | |
1652 | else if (enable_hsclk) | |
1653 | pwstate = DSI_PLL_POWER_ON_HSCLK; | |
1654 | else if (enable_hsdiv) | |
1655 | pwstate = DSI_PLL_POWER_ON_DIV; | |
1656 | else | |
1657 | pwstate = DSI_PLL_POWER_OFF; | |
1658 | ||
a72b64b9 | 1659 | r = dsi_pll_power(dsidev, pwstate); |
3de7a1dc TV |
1660 | |
1661 | if (r) | |
1662 | goto err1; | |
1663 | ||
1664 | DSSDBG("PLL init done\n"); | |
1665 | ||
1666 | return 0; | |
1667 | err1: | |
f1da39d9 AT |
1668 | if (dsi->vdds_dsi_enabled) { |
1669 | regulator_disable(dsi->vdds_dsi_reg); | |
1670 | dsi->vdds_dsi_enabled = false; | |
2a89dc15 | 1671 | } |
3de7a1dc | 1672 | err0: |
a72b64b9 | 1673 | dsi_disable_scp_clk(dsidev); |
a72b64b9 | 1674 | dsi_enable_pll_clock(dsidev, 0); |
3de7a1dc TV |
1675 | return r; |
1676 | } | |
1677 | ||
a72b64b9 | 1678 | void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes) |
3de7a1dc | 1679 | { |
f1da39d9 AT |
1680 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1681 | ||
1682 | dsi->pll_locked = 0; | |
a72b64b9 | 1683 | dsi_pll_power(dsidev, DSI_PLL_POWER_OFF); |
2a89dc15 | 1684 | if (disconnect_lanes) { |
f1da39d9 AT |
1685 | WARN_ON(!dsi->vdds_dsi_enabled); |
1686 | regulator_disable(dsi->vdds_dsi_reg); | |
1687 | dsi->vdds_dsi_enabled = false; | |
2a89dc15 | 1688 | } |
24c1ae41 | 1689 | |
a72b64b9 | 1690 | dsi_disable_scp_clk(dsidev); |
a72b64b9 | 1691 | dsi_enable_pll_clock(dsidev, 0); |
24c1ae41 | 1692 | |
3de7a1dc TV |
1693 | DSSDBG("PLL uninit done\n"); |
1694 | } | |
1695 | ||
5a8b572d AT |
1696 | static void dsi_dump_dsidev_clocks(struct platform_device *dsidev, |
1697 | struct seq_file *s) | |
3de7a1dc | 1698 | { |
f1da39d9 AT |
1699 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
1700 | struct dsi_clock_info *cinfo = &dsi->current_cinfo; | |
89a35e51 | 1701 | enum omap_dss_clk_source dispc_clk_src, dsi_clk_src; |
11ee9606 | 1702 | int dsi_module = dsi->module_id; |
067a57e4 AT |
1703 | |
1704 | dispc_clk_src = dss_get_dispc_clk_source(); | |
5a8b572d | 1705 | dsi_clk_src = dss_get_dsi_clk_source(dsi_module); |
3de7a1dc | 1706 | |
4fbafaf3 TV |
1707 | if (dsi_runtime_get(dsidev)) |
1708 | return; | |
3de7a1dc | 1709 | |
5a8b572d | 1710 | seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1); |
3de7a1dc | 1711 | |
b6e695ab | 1712 | seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin); |
3de7a1dc TV |
1713 | |
1714 | seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn); | |
1715 | ||
1716 | seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n", | |
1717 | cinfo->clkin4ddr, cinfo->regm); | |
1718 | ||
84309f16 AT |
1719 | seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n", |
1720 | dss_feat_get_clk_source_name(dsi_module == 0 ? | |
1721 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : | |
1722 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC), | |
1bb47835 AT |
1723 | cinfo->dsi_pll_hsdiv_dispc_clk, |
1724 | cinfo->regm_dispc, | |
89a35e51 | 1725 | dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
63cf28ac | 1726 | "off" : "on"); |
3de7a1dc | 1727 | |
84309f16 AT |
1728 | seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n", |
1729 | dss_feat_get_clk_source_name(dsi_module == 0 ? | |
1730 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : | |
1731 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI), | |
1bb47835 AT |
1732 | cinfo->dsi_pll_hsdiv_dsi_clk, |
1733 | cinfo->regm_dsi, | |
89a35e51 | 1734 | dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
63cf28ac | 1735 | "off" : "on"); |
3de7a1dc | 1736 | |
5a8b572d | 1737 | seq_printf(s, "- DSI%d -\n", dsi_module + 1); |
3de7a1dc | 1738 | |
067a57e4 AT |
1739 | seq_printf(s, "dsi fclk source = %s (%s)\n", |
1740 | dss_get_generic_clk_source_name(dsi_clk_src), | |
1741 | dss_feat_get_clk_source_name(dsi_clk_src)); | |
3de7a1dc | 1742 | |
a72b64b9 | 1743 | seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev)); |
3de7a1dc TV |
1744 | |
1745 | seq_printf(s, "DDR_CLK\t\t%lu\n", | |
1746 | cinfo->clkin4ddr / 4); | |
1747 | ||
a72b64b9 | 1748 | seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev)); |
3de7a1dc TV |
1749 | |
1750 | seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk); | |
1751 | ||
4fbafaf3 | 1752 | dsi_runtime_put(dsidev); |
3de7a1dc TV |
1753 | } |
1754 | ||
5a8b572d AT |
1755 | void dsi_dump_clocks(struct seq_file *s) |
1756 | { | |
1757 | struct platform_device *dsidev; | |
1758 | int i; | |
1759 | ||
1760 | for (i = 0; i < MAX_NUM_DSI; i++) { | |
1761 | dsidev = dsi_get_dsidev_from_id(i); | |
1762 | if (dsidev) | |
1763 | dsi_dump_dsidev_clocks(dsidev, s); | |
1764 | } | |
1765 | } | |
1766 | ||
dfc0fd8d | 1767 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
5a8b572d AT |
1768 | static void dsi_dump_dsidev_irqs(struct platform_device *dsidev, |
1769 | struct seq_file *s) | |
dfc0fd8d | 1770 | { |
f1da39d9 | 1771 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
dfc0fd8d TV |
1772 | unsigned long flags; |
1773 | struct dsi_irq_stats stats; | |
1774 | ||
f1da39d9 | 1775 | spin_lock_irqsave(&dsi->irq_stats_lock, flags); |
dfc0fd8d | 1776 | |
f1da39d9 AT |
1777 | stats = dsi->irq_stats; |
1778 | memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats)); | |
1779 | dsi->irq_stats.last_reset = jiffies; | |
dfc0fd8d | 1780 | |
f1da39d9 | 1781 | spin_unlock_irqrestore(&dsi->irq_stats_lock, flags); |
dfc0fd8d TV |
1782 | |
1783 | seq_printf(s, "period %u ms\n", | |
1784 | jiffies_to_msecs(jiffies - stats.last_reset)); | |
1785 | ||
1786 | seq_printf(s, "irqs %d\n", stats.irq_count); | |
1787 | #define PIS(x) \ | |
1788 | seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]); | |
1789 | ||
11ee9606 | 1790 | seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1); |
dfc0fd8d TV |
1791 | PIS(VC0); |
1792 | PIS(VC1); | |
1793 | PIS(VC2); | |
1794 | PIS(VC3); | |
1795 | PIS(WAKEUP); | |
1796 | PIS(RESYNC); | |
1797 | PIS(PLL_LOCK); | |
1798 | PIS(PLL_UNLOCK); | |
1799 | PIS(PLL_RECALL); | |
1800 | PIS(COMPLEXIO_ERR); | |
1801 | PIS(HS_TX_TIMEOUT); | |
1802 | PIS(LP_RX_TIMEOUT); | |
1803 | PIS(TE_TRIGGER); | |
1804 | PIS(ACK_TRIGGER); | |
1805 | PIS(SYNC_LOST); | |
1806 | PIS(LDO_POWER_GOOD); | |
1807 | PIS(TA_TIMEOUT); | |
1808 | #undef PIS | |
1809 | ||
1810 | #define PIS(x) \ | |
1811 | seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \ | |
1812 | stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \ | |
1813 | stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \ | |
1814 | stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \ | |
1815 | stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]); | |
1816 | ||
1817 | seq_printf(s, "-- VC interrupts --\n"); | |
1818 | PIS(CS); | |
1819 | PIS(ECC_CORR); | |
1820 | PIS(PACKET_SENT); | |
1821 | PIS(FIFO_TX_OVF); | |
1822 | PIS(FIFO_RX_OVF); | |
1823 | PIS(BTA); | |
1824 | PIS(ECC_NO_CORR); | |
1825 | PIS(FIFO_TX_UDF); | |
1826 | PIS(PP_BUSY_CHANGE); | |
1827 | #undef PIS | |
1828 | ||
1829 | #define PIS(x) \ | |
1830 | seq_printf(s, "%-20s %10d\n", #x, \ | |
1831 | stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]); | |
1832 | ||
1833 | seq_printf(s, "-- CIO interrupts --\n"); | |
1834 | PIS(ERRSYNCESC1); | |
1835 | PIS(ERRSYNCESC2); | |
1836 | PIS(ERRSYNCESC3); | |
1837 | PIS(ERRESC1); | |
1838 | PIS(ERRESC2); | |
1839 | PIS(ERRESC3); | |
1840 | PIS(ERRCONTROL1); | |
1841 | PIS(ERRCONTROL2); | |
1842 | PIS(ERRCONTROL3); | |
1843 | PIS(STATEULPS1); | |
1844 | PIS(STATEULPS2); | |
1845 | PIS(STATEULPS3); | |
1846 | PIS(ERRCONTENTIONLP0_1); | |
1847 | PIS(ERRCONTENTIONLP1_1); | |
1848 | PIS(ERRCONTENTIONLP0_2); | |
1849 | PIS(ERRCONTENTIONLP1_2); | |
1850 | PIS(ERRCONTENTIONLP0_3); | |
1851 | PIS(ERRCONTENTIONLP1_3); | |
1852 | PIS(ULPSACTIVENOT_ALL0); | |
1853 | PIS(ULPSACTIVENOT_ALL1); | |
1854 | #undef PIS | |
1855 | } | |
dfc0fd8d | 1856 | |
5a8b572d | 1857 | static void dsi1_dump_irqs(struct seq_file *s) |
3de7a1dc | 1858 | { |
a72b64b9 AT |
1859 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); |
1860 | ||
5a8b572d AT |
1861 | dsi_dump_dsidev_irqs(dsidev, s); |
1862 | } | |
1863 | ||
1864 | static void dsi2_dump_irqs(struct seq_file *s) | |
1865 | { | |
1866 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); | |
1867 | ||
1868 | dsi_dump_dsidev_irqs(dsidev, s); | |
1869 | } | |
5a8b572d AT |
1870 | #endif |
1871 | ||
1872 | static void dsi_dump_dsidev_regs(struct platform_device *dsidev, | |
1873 | struct seq_file *s) | |
1874 | { | |
a72b64b9 | 1875 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r)) |
3de7a1dc | 1876 | |
4fbafaf3 TV |
1877 | if (dsi_runtime_get(dsidev)) |
1878 | return; | |
a72b64b9 | 1879 | dsi_enable_scp_clk(dsidev); |
3de7a1dc TV |
1880 | |
1881 | DUMPREG(DSI_REVISION); | |
1882 | DUMPREG(DSI_SYSCONFIG); | |
1883 | DUMPREG(DSI_SYSSTATUS); | |
1884 | DUMPREG(DSI_IRQSTATUS); | |
1885 | DUMPREG(DSI_IRQENABLE); | |
1886 | DUMPREG(DSI_CTRL); | |
1887 | DUMPREG(DSI_COMPLEXIO_CFG1); | |
1888 | DUMPREG(DSI_COMPLEXIO_IRQ_STATUS); | |
1889 | DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE); | |
1890 | DUMPREG(DSI_CLK_CTRL); | |
1891 | DUMPREG(DSI_TIMING1); | |
1892 | DUMPREG(DSI_TIMING2); | |
1893 | DUMPREG(DSI_VM_TIMING1); | |
1894 | DUMPREG(DSI_VM_TIMING2); | |
1895 | DUMPREG(DSI_VM_TIMING3); | |
1896 | DUMPREG(DSI_CLK_TIMING); | |
1897 | DUMPREG(DSI_TX_FIFO_VC_SIZE); | |
1898 | DUMPREG(DSI_RX_FIFO_VC_SIZE); | |
1899 | DUMPREG(DSI_COMPLEXIO_CFG2); | |
1900 | DUMPREG(DSI_RX_FIFO_VC_FULLNESS); | |
1901 | DUMPREG(DSI_VM_TIMING4); | |
1902 | DUMPREG(DSI_TX_FIFO_VC_EMPTINESS); | |
1903 | DUMPREG(DSI_VM_TIMING5); | |
1904 | DUMPREG(DSI_VM_TIMING6); | |
1905 | DUMPREG(DSI_VM_TIMING7); | |
1906 | DUMPREG(DSI_STOPCLK_TIMING); | |
1907 | ||
1908 | DUMPREG(DSI_VC_CTRL(0)); | |
1909 | DUMPREG(DSI_VC_TE(0)); | |
1910 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(0)); | |
1911 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0)); | |
1912 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0)); | |
1913 | DUMPREG(DSI_VC_IRQSTATUS(0)); | |
1914 | DUMPREG(DSI_VC_IRQENABLE(0)); | |
1915 | ||
1916 | DUMPREG(DSI_VC_CTRL(1)); | |
1917 | DUMPREG(DSI_VC_TE(1)); | |
1918 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(1)); | |
1919 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1)); | |
1920 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1)); | |
1921 | DUMPREG(DSI_VC_IRQSTATUS(1)); | |
1922 | DUMPREG(DSI_VC_IRQENABLE(1)); | |
1923 | ||
1924 | DUMPREG(DSI_VC_CTRL(2)); | |
1925 | DUMPREG(DSI_VC_TE(2)); | |
1926 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(2)); | |
1927 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2)); | |
1928 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2)); | |
1929 | DUMPREG(DSI_VC_IRQSTATUS(2)); | |
1930 | DUMPREG(DSI_VC_IRQENABLE(2)); | |
1931 | ||
1932 | DUMPREG(DSI_VC_CTRL(3)); | |
1933 | DUMPREG(DSI_VC_TE(3)); | |
1934 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(3)); | |
1935 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3)); | |
1936 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3)); | |
1937 | DUMPREG(DSI_VC_IRQSTATUS(3)); | |
1938 | DUMPREG(DSI_VC_IRQENABLE(3)); | |
1939 | ||
1940 | DUMPREG(DSI_DSIPHY_CFG0); | |
1941 | DUMPREG(DSI_DSIPHY_CFG1); | |
1942 | DUMPREG(DSI_DSIPHY_CFG2); | |
1943 | DUMPREG(DSI_DSIPHY_CFG5); | |
1944 | ||
1945 | DUMPREG(DSI_PLL_CONTROL); | |
1946 | DUMPREG(DSI_PLL_STATUS); | |
1947 | DUMPREG(DSI_PLL_GO); | |
1948 | DUMPREG(DSI_PLL_CONFIGURATION1); | |
1949 | DUMPREG(DSI_PLL_CONFIGURATION2); | |
1950 | ||
a72b64b9 | 1951 | dsi_disable_scp_clk(dsidev); |
4fbafaf3 | 1952 | dsi_runtime_put(dsidev); |
3de7a1dc TV |
1953 | #undef DUMPREG |
1954 | } | |
1955 | ||
5a8b572d AT |
1956 | static void dsi1_dump_regs(struct seq_file *s) |
1957 | { | |
1958 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); | |
1959 | ||
1960 | dsi_dump_dsidev_regs(dsidev, s); | |
1961 | } | |
1962 | ||
1963 | static void dsi2_dump_regs(struct seq_file *s) | |
1964 | { | |
1965 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); | |
1966 | ||
1967 | dsi_dump_dsidev_regs(dsidev, s); | |
1968 | } | |
1969 | ||
cc5c1850 | 1970 | enum dsi_cio_power_state { |
3de7a1dc TV |
1971 | DSI_COMPLEXIO_POWER_OFF = 0x0, |
1972 | DSI_COMPLEXIO_POWER_ON = 0x1, | |
1973 | DSI_COMPLEXIO_POWER_ULPS = 0x2, | |
1974 | }; | |
1975 | ||
a72b64b9 AT |
1976 | static int dsi_cio_power(struct platform_device *dsidev, |
1977 | enum dsi_cio_power_state state) | |
3de7a1dc TV |
1978 | { |
1979 | int t = 0; | |
1980 | ||
1981 | /* PWR_CMD */ | |
a72b64b9 | 1982 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27); |
3de7a1dc TV |
1983 | |
1984 | /* PWR_STATUS */ | |
a72b64b9 AT |
1985 | while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1), |
1986 | 26, 25) != state) { | |
24be78b3 | 1987 | if (++t > 1000) { |
3de7a1dc TV |
1988 | DSSERR("failed to set complexio power state to " |
1989 | "%d\n", state); | |
1990 | return -ENODEV; | |
1991 | } | |
24be78b3 | 1992 | udelay(1); |
3de7a1dc TV |
1993 | } |
1994 | ||
1995 | return 0; | |
1996 | } | |
1997 | ||
0c65622b AT |
1998 | static unsigned dsi_get_line_buf_size(struct platform_device *dsidev) |
1999 | { | |
2000 | int val; | |
2001 | ||
2002 | /* line buffer on OMAP3 is 1024 x 24bits */ | |
2003 | /* XXX: for some reason using full buffer size causes | |
2004 | * considerable TX slowdown with update sizes that fill the | |
2005 | * whole buffer */ | |
2006 | if (!dss_has_feature(FEAT_DSI_GNQ)) | |
2007 | return 1023 * 3; | |
2008 | ||
2009 | val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */ | |
2010 | ||
2011 | switch (val) { | |
2012 | case 1: | |
2013 | return 512 * 3; /* 512x24 bits */ | |
2014 | case 2: | |
2015 | return 682 * 3; /* 682x24 bits */ | |
2016 | case 3: | |
2017 | return 853 * 3; /* 853x24 bits */ | |
2018 | case 4: | |
2019 | return 1024 * 3; /* 1024x24 bits */ | |
2020 | case 5: | |
2021 | return 1194 * 3; /* 1194x24 bits */ | |
2022 | case 6: | |
2023 | return 1365 * 3; /* 1365x24 bits */ | |
2ac80fbe TV |
2024 | case 7: |
2025 | return 1920 * 3; /* 1920x24 bits */ | |
0c65622b AT |
2026 | default: |
2027 | BUG(); | |
c6eee968 | 2028 | return 0; |
0c65622b AT |
2029 | } |
2030 | } | |
2031 | ||
9e7e9372 | 2032 | static int dsi_set_lane_config(struct platform_device *dsidev) |
3de7a1dc | 2033 | { |
48368395 TV |
2034 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2035 | static const u8 offsets[] = { 0, 4, 8, 12, 16 }; | |
2036 | static const enum dsi_lane_function functions[] = { | |
2037 | DSI_LANE_CLK, | |
2038 | DSI_LANE_DATA1, | |
2039 | DSI_LANE_DATA2, | |
2040 | DSI_LANE_DATA3, | |
2041 | DSI_LANE_DATA4, | |
2042 | }; | |
3de7a1dc | 2043 | u32 r; |
48368395 | 2044 | int i; |
3de7a1dc | 2045 | |
a72b64b9 | 2046 | r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1); |
48368395 TV |
2047 | |
2048 | for (i = 0; i < dsi->num_lanes_used; ++i) { | |
2049 | unsigned offset = offsets[i]; | |
2050 | unsigned polarity, lane_number; | |
2051 | unsigned t; | |
2052 | ||
2053 | for (t = 0; t < dsi->num_lanes_supported; ++t) | |
2054 | if (dsi->lanes[t].function == functions[i]) | |
2055 | break; | |
2056 | ||
2057 | if (t == dsi->num_lanes_supported) | |
2058 | return -EINVAL; | |
2059 | ||
2060 | lane_number = t; | |
2061 | polarity = dsi->lanes[t].polarity; | |
2062 | ||
2063 | r = FLD_MOD(r, lane_number + 1, offset + 2, offset); | |
2064 | r = FLD_MOD(r, polarity, offset + 3, offset + 3); | |
75d7247c | 2065 | } |
75d7247c | 2066 | |
48368395 TV |
2067 | /* clear the unused lanes */ |
2068 | for (; i < dsi->num_lanes_supported; ++i) { | |
2069 | unsigned offset = offsets[i]; | |
2070 | ||
2071 | r = FLD_MOD(r, 0, offset + 2, offset); | |
2072 | r = FLD_MOD(r, 0, offset + 3, offset + 3); | |
75d7247c | 2073 | } |
3de7a1dc | 2074 | |
48368395 | 2075 | dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r); |
3de7a1dc | 2076 | |
48368395 | 2077 | return 0; |
3de7a1dc TV |
2078 | } |
2079 | ||
a72b64b9 | 2080 | static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns) |
3de7a1dc | 2081 | { |
f1da39d9 AT |
2082 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2083 | ||
3de7a1dc | 2084 | /* convert time in ns to ddr ticks, rounding up */ |
f1da39d9 | 2085 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; |
3de7a1dc TV |
2086 | return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000; |
2087 | } | |
2088 | ||
a72b64b9 | 2089 | static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr) |
3de7a1dc | 2090 | { |
f1da39d9 AT |
2091 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2092 | ||
2093 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; | |
3de7a1dc TV |
2094 | return ddr * 1000 * 1000 / (ddr_clk / 1000); |
2095 | } | |
2096 | ||
a72b64b9 | 2097 | static void dsi_cio_timings(struct platform_device *dsidev) |
3de7a1dc TV |
2098 | { |
2099 | u32 r; | |
2100 | u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit; | |
2101 | u32 tlpx_half, tclk_trail, tclk_zero; | |
2102 | u32 tclk_prepare; | |
2103 | ||
2104 | /* calculate timings */ | |
2105 | ||
2106 | /* 1 * DDR_CLK = 2 * UI */ | |
2107 | ||
2108 | /* min 40ns + 4*UI max 85ns + 6*UI */ | |
a72b64b9 | 2109 | ths_prepare = ns2ddr(dsidev, 70) + 2; |
3de7a1dc TV |
2110 | |
2111 | /* min 145ns + 10*UI */ | |
a72b64b9 | 2112 | ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2; |
3de7a1dc TV |
2113 | |
2114 | /* min max(8*UI, 60ns+4*UI) */ | |
a72b64b9 | 2115 | ths_trail = ns2ddr(dsidev, 60) + 5; |
3de7a1dc TV |
2116 | |
2117 | /* min 100ns */ | |
a72b64b9 | 2118 | ths_exit = ns2ddr(dsidev, 145); |
3de7a1dc TV |
2119 | |
2120 | /* tlpx min 50n */ | |
a72b64b9 | 2121 | tlpx_half = ns2ddr(dsidev, 25); |
3de7a1dc TV |
2122 | |
2123 | /* min 60ns */ | |
a72b64b9 | 2124 | tclk_trail = ns2ddr(dsidev, 60) + 2; |
3de7a1dc TV |
2125 | |
2126 | /* min 38ns, max 95ns */ | |
a72b64b9 | 2127 | tclk_prepare = ns2ddr(dsidev, 65); |
3de7a1dc TV |
2128 | |
2129 | /* min tclk-prepare + tclk-zero = 300ns */ | |
a72b64b9 | 2130 | tclk_zero = ns2ddr(dsidev, 260); |
3de7a1dc TV |
2131 | |
2132 | DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n", | |
a72b64b9 AT |
2133 | ths_prepare, ddr2ns(dsidev, ths_prepare), |
2134 | ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero)); | |
3de7a1dc | 2135 | DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n", |
a72b64b9 AT |
2136 | ths_trail, ddr2ns(dsidev, ths_trail), |
2137 | ths_exit, ddr2ns(dsidev, ths_exit)); | |
3de7a1dc TV |
2138 | |
2139 | DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), " | |
2140 | "tclk_zero %u (%uns)\n", | |
a72b64b9 AT |
2141 | tlpx_half, ddr2ns(dsidev, tlpx_half), |
2142 | tclk_trail, ddr2ns(dsidev, tclk_trail), | |
2143 | tclk_zero, ddr2ns(dsidev, tclk_zero)); | |
3de7a1dc | 2144 | DSSDBG("tclk_prepare %u (%uns)\n", |
a72b64b9 | 2145 | tclk_prepare, ddr2ns(dsidev, tclk_prepare)); |
3de7a1dc TV |
2146 | |
2147 | /* program timings */ | |
2148 | ||
a72b64b9 | 2149 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
3de7a1dc TV |
2150 | r = FLD_MOD(r, ths_prepare, 31, 24); |
2151 | r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16); | |
2152 | r = FLD_MOD(r, ths_trail, 15, 8); | |
2153 | r = FLD_MOD(r, ths_exit, 7, 0); | |
a72b64b9 | 2154 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r); |
3de7a1dc | 2155 | |
a72b64b9 | 2156 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
e84dc1cc | 2157 | r = FLD_MOD(r, tlpx_half, 20, 16); |
3de7a1dc TV |
2158 | r = FLD_MOD(r, tclk_trail, 15, 8); |
2159 | r = FLD_MOD(r, tclk_zero, 7, 0); | |
77ccbfbb TV |
2160 | |
2161 | if (dss_has_feature(FEAT_DSI_PHY_DCC)) { | |
2162 | r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */ | |
2163 | r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */ | |
2164 | r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */ | |
2165 | } | |
2166 | ||
a72b64b9 | 2167 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r); |
3de7a1dc | 2168 | |
a72b64b9 | 2169 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
3de7a1dc | 2170 | r = FLD_MOD(r, tclk_prepare, 7, 0); |
a72b64b9 | 2171 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r); |
3de7a1dc TV |
2172 | } |
2173 | ||
9b4362f2 | 2174 | /* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */ |
9e7e9372 | 2175 | static void dsi_cio_enable_lane_override(struct platform_device *dsidev, |
9b4362f2 | 2176 | unsigned mask_p, unsigned mask_n) |
0a0ee46b | 2177 | { |
75d7247c | 2178 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
9b4362f2 TV |
2179 | int i; |
2180 | u32 l; | |
d9820850 | 2181 | u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26; |
0a0ee46b | 2182 | |
9b4362f2 TV |
2183 | l = 0; |
2184 | ||
2185 | for (i = 0; i < dsi->num_lanes_supported; ++i) { | |
2186 | unsigned p = dsi->lanes[i].polarity; | |
2187 | ||
2188 | if (mask_p & (1 << i)) | |
2189 | l |= 1 << (i * 2 + (p ? 0 : 1)); | |
2190 | ||
2191 | if (mask_n & (1 << i)) | |
2192 | l |= 1 << (i * 2 + (p ? 1 : 0)); | |
2193 | } | |
2194 | ||
0a0ee46b TV |
2195 | /* |
2196 | * Bits in REGLPTXSCPDAT4TO0DXDY: | |
2197 | * 17: DY0 18: DX0 | |
2198 | * 19: DY1 20: DX1 | |
2199 | * 21: DY2 22: DX2 | |
75d7247c AT |
2200 | * 23: DY3 24: DX3 |
2201 | * 25: DY4 26: DX4 | |
0a0ee46b TV |
2202 | */ |
2203 | ||
2204 | /* Set the lane override configuration */ | |
a72b64b9 AT |
2205 | |
2206 | /* REGLPTXSCPDAT4TO0DXDY */ | |
75d7247c | 2207 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17); |
0a0ee46b TV |
2208 | |
2209 | /* Enable lane override */ | |
a72b64b9 AT |
2210 | |
2211 | /* ENLPTXSCPDAT */ | |
2212 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27); | |
0a0ee46b TV |
2213 | } |
2214 | ||
a72b64b9 | 2215 | static void dsi_cio_disable_lane_override(struct platform_device *dsidev) |
0a0ee46b TV |
2216 | { |
2217 | /* Disable lane override */ | |
a72b64b9 | 2218 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */ |
0a0ee46b | 2219 | /* Reset the lane override configuration */ |
a72b64b9 AT |
2220 | /* REGLPTXSCPDAT4TO0DXDY */ |
2221 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17); | |
0a0ee46b | 2222 | } |
3de7a1dc | 2223 | |
9e7e9372 | 2224 | static int dsi_cio_wait_tx_clk_esc_reset(struct platform_device *dsidev) |
03329ace | 2225 | { |
8dc0766f TV |
2226 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2227 | int t, i; | |
2228 | bool in_use[DSI_MAX_NR_LANES]; | |
2229 | static const u8 offsets_old[] = { 28, 27, 26 }; | |
2230 | static const u8 offsets_new[] = { 24, 25, 26, 27, 28 }; | |
2231 | const u8 *offsets; | |
2232 | ||
2233 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) | |
2234 | offsets = offsets_old; | |
2235 | else | |
2236 | offsets = offsets_new; | |
03329ace | 2237 | |
8dc0766f TV |
2238 | for (i = 0; i < dsi->num_lanes_supported; ++i) |
2239 | in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED; | |
03329ace TV |
2240 | |
2241 | t = 100000; | |
2242 | while (true) { | |
2243 | u32 l; | |
03329ace TV |
2244 | int ok; |
2245 | ||
a72b64b9 | 2246 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
03329ace TV |
2247 | |
2248 | ok = 0; | |
8dc0766f TV |
2249 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
2250 | if (!in_use[i] || (l & (1 << offsets[i]))) | |
03329ace TV |
2251 | ok++; |
2252 | } | |
2253 | ||
8dc0766f | 2254 | if (ok == dsi->num_lanes_supported) |
03329ace TV |
2255 | break; |
2256 | ||
2257 | if (--t == 0) { | |
8dc0766f TV |
2258 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
2259 | if (!in_use[i] || (l & (1 << offsets[i]))) | |
03329ace TV |
2260 | continue; |
2261 | ||
2262 | DSSERR("CIO TXCLKESC%d domain not coming " \ | |
2263 | "out of reset\n", i); | |
2264 | } | |
2265 | return -EIO; | |
2266 | } | |
2267 | } | |
2268 | ||
2269 | return 0; | |
2270 | } | |
2271 | ||
85f17e8e | 2272 | /* return bitmask of enabled lanes, lane0 being the lsb */ |
9e7e9372 | 2273 | static unsigned dsi_get_lane_mask(struct platform_device *dsidev) |
5bc416cb | 2274 | { |
85f17e8e TV |
2275 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2276 | unsigned mask = 0; | |
2277 | int i; | |
5bc416cb | 2278 | |
85f17e8e TV |
2279 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
2280 | if (dsi->lanes[i].function != DSI_LANE_UNUSED) | |
2281 | mask |= 1 << i; | |
2282 | } | |
5bc416cb | 2283 | |
85f17e8e | 2284 | return mask; |
5bc416cb TV |
2285 | } |
2286 | ||
9e7e9372 | 2287 | static int dsi_cio_init(struct platform_device *dsidev) |
3de7a1dc | 2288 | { |
f1da39d9 | 2289 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
65c62bb9 | 2290 | int r; |
40885ab3 | 2291 | u32 l; |
3de7a1dc | 2292 | |
702d267e | 2293 | DSSDBG("DSI CIO init starts"); |
3de7a1dc | 2294 | |
9e7e9372 | 2295 | r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
5bc416cb TV |
2296 | if (r) |
2297 | return r; | |
d1f5857e | 2298 | |
a72b64b9 | 2299 | dsi_enable_scp_clk(dsidev); |
40885ab3 | 2300 | |
3de7a1dc TV |
2301 | /* A dummy read using the SCP interface to any DSIPHY register is |
2302 | * required after DSIPHY reset to complete the reset of the DSI complex | |
2303 | * I/O. */ | |
a72b64b9 | 2304 | dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
3de7a1dc | 2305 | |
a72b64b9 | 2306 | if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) { |
65c62bb9 TV |
2307 | DSSERR("CIO SCP Clock domain not coming out of reset.\n"); |
2308 | r = -EIO; | |
2309 | goto err_scp_clk_dom; | |
3de7a1dc TV |
2310 | } |
2311 | ||
9e7e9372 | 2312 | r = dsi_set_lane_config(dsidev); |
48368395 TV |
2313 | if (r) |
2314 | goto err_scp_clk_dom; | |
3de7a1dc | 2315 | |
40885ab3 | 2316 | /* set TX STOP MODE timer to maximum for this operation */ |
a72b64b9 | 2317 | l = dsi_read_reg(dsidev, DSI_TIMING1); |
40885ab3 TV |
2318 | l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
2319 | l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */ | |
2320 | l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */ | |
2321 | l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */ | |
a72b64b9 | 2322 | dsi_write_reg(dsidev, DSI_TIMING1, l); |
40885ab3 | 2323 | |
f1da39d9 | 2324 | if (dsi->ulps_enabled) { |
9b4362f2 TV |
2325 | unsigned mask_p; |
2326 | int i; | |
75d7247c | 2327 | |
65c62bb9 TV |
2328 | DSSDBG("manual ulps exit\n"); |
2329 | ||
40885ab3 TV |
2330 | /* ULPS is exited by Mark-1 state for 1ms, followed by |
2331 | * stop state. DSS HW cannot do this via the normal | |
2332 | * ULPS exit sequence, as after reset the DSS HW thinks | |
2333 | * that we are not in ULPS mode, and refuses to send the | |
2334 | * sequence. So we need to send the ULPS exit sequence | |
9b4362f2 TV |
2335 | * manually by setting positive lines high and negative lines |
2336 | * low for 1ms. | |
40885ab3 TV |
2337 | */ |
2338 | ||
9b4362f2 | 2339 | mask_p = 0; |
75d7247c | 2340 | |
9b4362f2 TV |
2341 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
2342 | if (dsi->lanes[i].function == DSI_LANE_UNUSED) | |
2343 | continue; | |
2344 | mask_p |= 1 << i; | |
2345 | } | |
75d7247c | 2346 | |
9e7e9372 | 2347 | dsi_cio_enable_lane_override(dsidev, mask_p, 0); |
40885ab3 | 2348 | } |
3de7a1dc | 2349 | |
a72b64b9 | 2350 | r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON); |
3de7a1dc | 2351 | if (r) |
65c62bb9 TV |
2352 | goto err_cio_pwr; |
2353 | ||
a72b64b9 | 2354 | if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) { |
65c62bb9 TV |
2355 | DSSERR("CIO PWR clock domain not coming out of reset.\n"); |
2356 | r = -ENODEV; | |
2357 | goto err_cio_pwr_dom; | |
2358 | } | |
2359 | ||
a72b64b9 AT |
2360 | dsi_if_enable(dsidev, true); |
2361 | dsi_if_enable(dsidev, false); | |
2362 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */ | |
3de7a1dc | 2363 | |
9e7e9372 | 2364 | r = dsi_cio_wait_tx_clk_esc_reset(dsidev); |
03329ace TV |
2365 | if (r) |
2366 | goto err_tx_clk_esc_rst; | |
2367 | ||
f1da39d9 | 2368 | if (dsi->ulps_enabled) { |
40885ab3 TV |
2369 | /* Keep Mark-1 state for 1ms (as per DSI spec) */ |
2370 | ktime_t wait = ns_to_ktime(1000 * 1000); | |
2371 | set_current_state(TASK_UNINTERRUPTIBLE); | |
2372 | schedule_hrtimeout(&wait, HRTIMER_MODE_REL); | |
2373 | ||
2374 | /* Disable the override. The lanes should be set to Mark-11 | |
2375 | * state by the HW */ | |
a72b64b9 | 2376 | dsi_cio_disable_lane_override(dsidev); |
40885ab3 TV |
2377 | } |
2378 | ||
2379 | /* FORCE_TX_STOP_MODE_IO */ | |
a72b64b9 | 2380 | REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15); |
40885ab3 | 2381 | |
a72b64b9 | 2382 | dsi_cio_timings(dsidev); |
3de7a1dc | 2383 | |
dca2b152 | 2384 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
8af6ff01 AT |
2385 | /* DDR_CLK_ALWAYS_ON */ |
2386 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, | |
0b3ffe39 | 2387 | dsi->vm_timings.ddr_clk_always_on, 13, 13); |
8af6ff01 AT |
2388 | } |
2389 | ||
f1da39d9 | 2390 | dsi->ulps_enabled = false; |
3de7a1dc TV |
2391 | |
2392 | DSSDBG("CIO init done\n"); | |
65c62bb9 TV |
2393 | |
2394 | return 0; | |
2395 | ||
03329ace | 2396 | err_tx_clk_esc_rst: |
a72b64b9 | 2397 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */ |
65c62bb9 | 2398 | err_cio_pwr_dom: |
a72b64b9 | 2399 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
65c62bb9 | 2400 | err_cio_pwr: |
f1da39d9 | 2401 | if (dsi->ulps_enabled) |
a72b64b9 | 2402 | dsi_cio_disable_lane_override(dsidev); |
65c62bb9 | 2403 | err_scp_clk_dom: |
a72b64b9 | 2404 | dsi_disable_scp_clk(dsidev); |
9e7e9372 | 2405 | dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
3de7a1dc TV |
2406 | return r; |
2407 | } | |
2408 | ||
9e7e9372 | 2409 | static void dsi_cio_uninit(struct platform_device *dsidev) |
3de7a1dc | 2410 | { |
11ee9606 | 2411 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
f1da39d9 | 2412 | |
8af6ff01 AT |
2413 | /* DDR_CLK_ALWAYS_ON */ |
2414 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); | |
2415 | ||
a72b64b9 AT |
2416 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
2417 | dsi_disable_scp_clk(dsidev); | |
9e7e9372 | 2418 | dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
3de7a1dc TV |
2419 | } |
2420 | ||
a72b64b9 AT |
2421 | static void dsi_config_tx_fifo(struct platform_device *dsidev, |
2422 | enum fifo_size size1, enum fifo_size size2, | |
3de7a1dc TV |
2423 | enum fifo_size size3, enum fifo_size size4) |
2424 | { | |
f1da39d9 | 2425 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
2426 | u32 r = 0; |
2427 | int add = 0; | |
2428 | int i; | |
2429 | ||
f1da39d9 AT |
2430 | dsi->vc[0].fifo_size = size1; |
2431 | dsi->vc[1].fifo_size = size2; | |
2432 | dsi->vc[2].fifo_size = size3; | |
2433 | dsi->vc[3].fifo_size = size4; | |
3de7a1dc TV |
2434 | |
2435 | for (i = 0; i < 4; i++) { | |
2436 | u8 v; | |
f1da39d9 | 2437 | int size = dsi->vc[i].fifo_size; |
3de7a1dc TV |
2438 | |
2439 | if (add + size > 4) { | |
2440 | DSSERR("Illegal FIFO configuration\n"); | |
2441 | BUG(); | |
c6eee968 | 2442 | return; |
3de7a1dc TV |
2443 | } |
2444 | ||
2445 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); | |
2446 | r |= v << (8 * i); | |
2447 | /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */ | |
2448 | add += size; | |
2449 | } | |
2450 | ||
a72b64b9 | 2451 | dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r); |
3de7a1dc TV |
2452 | } |
2453 | ||
a72b64b9 AT |
2454 | static void dsi_config_rx_fifo(struct platform_device *dsidev, |
2455 | enum fifo_size size1, enum fifo_size size2, | |
3de7a1dc TV |
2456 | enum fifo_size size3, enum fifo_size size4) |
2457 | { | |
f1da39d9 | 2458 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
2459 | u32 r = 0; |
2460 | int add = 0; | |
2461 | int i; | |
2462 | ||
f1da39d9 AT |
2463 | dsi->vc[0].fifo_size = size1; |
2464 | dsi->vc[1].fifo_size = size2; | |
2465 | dsi->vc[2].fifo_size = size3; | |
2466 | dsi->vc[3].fifo_size = size4; | |
3de7a1dc TV |
2467 | |
2468 | for (i = 0; i < 4; i++) { | |
2469 | u8 v; | |
f1da39d9 | 2470 | int size = dsi->vc[i].fifo_size; |
3de7a1dc TV |
2471 | |
2472 | if (add + size > 4) { | |
2473 | DSSERR("Illegal FIFO configuration\n"); | |
2474 | BUG(); | |
c6eee968 | 2475 | return; |
3de7a1dc TV |
2476 | } |
2477 | ||
2478 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); | |
2479 | r |= v << (8 * i); | |
2480 | /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */ | |
2481 | add += size; | |
2482 | } | |
2483 | ||
a72b64b9 | 2484 | dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r); |
3de7a1dc TV |
2485 | } |
2486 | ||
a72b64b9 | 2487 | static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev) |
3de7a1dc TV |
2488 | { |
2489 | u32 r; | |
2490 | ||
a72b64b9 | 2491 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
3de7a1dc | 2492 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
a72b64b9 | 2493 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
3de7a1dc | 2494 | |
a72b64b9 | 2495 | if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) { |
3de7a1dc TV |
2496 | DSSERR("TX_STOP bit not going down\n"); |
2497 | return -EIO; | |
2498 | } | |
2499 | ||
2500 | return 0; | |
2501 | } | |
2502 | ||
a72b64b9 | 2503 | static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel) |
cf398fb3 | 2504 | { |
a72b64b9 | 2505 | return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0); |
cf398fb3 AT |
2506 | } |
2507 | ||
2508 | static void dsi_packet_sent_handler_vp(void *data, u32 mask) | |
2509 | { | |
2e868dbe AT |
2510 | struct dsi_packet_sent_handler_data *vp_data = |
2511 | (struct dsi_packet_sent_handler_data *) data; | |
2512 | struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev); | |
f1da39d9 AT |
2513 | const int channel = dsi->update_channel; |
2514 | u8 bit = dsi->te_enabled ? 30 : 31; | |
cf398fb3 | 2515 | |
2e868dbe AT |
2516 | if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0) |
2517 | complete(vp_data->completion); | |
cf398fb3 AT |
2518 | } |
2519 | ||
a72b64b9 | 2520 | static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel) |
cf398fb3 | 2521 | { |
f1da39d9 | 2522 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2e868dbe AT |
2523 | DECLARE_COMPLETION_ONSTACK(completion); |
2524 | struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion }; | |
cf398fb3 AT |
2525 | int r = 0; |
2526 | u8 bit; | |
2527 | ||
f1da39d9 | 2528 | bit = dsi->te_enabled ? 30 : 31; |
cf398fb3 | 2529 | |
a72b64b9 | 2530 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
2e868dbe | 2531 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
cf398fb3 AT |
2532 | if (r) |
2533 | goto err0; | |
2534 | ||
2535 | /* Wait for completion only if TE_EN/TE_START is still set */ | |
a72b64b9 | 2536 | if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) { |
cf398fb3 AT |
2537 | if (wait_for_completion_timeout(&completion, |
2538 | msecs_to_jiffies(10)) == 0) { | |
2539 | DSSERR("Failed to complete previous frame transfer\n"); | |
2540 | r = -EIO; | |
2541 | goto err1; | |
2542 | } | |
2543 | } | |
2544 | ||
a72b64b9 | 2545 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
2e868dbe | 2546 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
cf398fb3 AT |
2547 | |
2548 | return 0; | |
2549 | err1: | |
a72b64b9 | 2550 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
2e868dbe | 2551 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
cf398fb3 AT |
2552 | err0: |
2553 | return r; | |
2554 | } | |
2555 | ||
2556 | static void dsi_packet_sent_handler_l4(void *data, u32 mask) | |
2557 | { | |
2e868dbe AT |
2558 | struct dsi_packet_sent_handler_data *l4_data = |
2559 | (struct dsi_packet_sent_handler_data *) data; | |
2560 | struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev); | |
f1da39d9 | 2561 | const int channel = dsi->update_channel; |
cf398fb3 | 2562 | |
2e868dbe AT |
2563 | if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0) |
2564 | complete(l4_data->completion); | |
cf398fb3 AT |
2565 | } |
2566 | ||
a72b64b9 | 2567 | static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel) |
cf398fb3 | 2568 | { |
cf398fb3 | 2569 | DECLARE_COMPLETION_ONSTACK(completion); |
2e868dbe AT |
2570 | struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion }; |
2571 | int r = 0; | |
cf398fb3 | 2572 | |
a72b64b9 | 2573 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
2e868dbe | 2574 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
cf398fb3 AT |
2575 | if (r) |
2576 | goto err0; | |
2577 | ||
2578 | /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */ | |
a72b64b9 | 2579 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) { |
cf398fb3 AT |
2580 | if (wait_for_completion_timeout(&completion, |
2581 | msecs_to_jiffies(10)) == 0) { | |
2582 | DSSERR("Failed to complete previous l4 transfer\n"); | |
2583 | r = -EIO; | |
2584 | goto err1; | |
2585 | } | |
2586 | } | |
2587 | ||
a72b64b9 | 2588 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
2e868dbe | 2589 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
cf398fb3 AT |
2590 | |
2591 | return 0; | |
2592 | err1: | |
a72b64b9 | 2593 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
2e868dbe | 2594 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
cf398fb3 AT |
2595 | err0: |
2596 | return r; | |
2597 | } | |
2598 | ||
a72b64b9 | 2599 | static int dsi_sync_vc(struct platform_device *dsidev, int channel) |
cf398fb3 | 2600 | { |
f1da39d9 AT |
2601 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2602 | ||
a72b64b9 | 2603 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
cf398fb3 AT |
2604 | |
2605 | WARN_ON(in_interrupt()); | |
2606 | ||
a72b64b9 | 2607 | if (!dsi_vc_is_enabled(dsidev, channel)) |
cf398fb3 AT |
2608 | return 0; |
2609 | ||
d6049144 AT |
2610 | switch (dsi->vc[channel].source) { |
2611 | case DSI_VC_SOURCE_VP: | |
a72b64b9 | 2612 | return dsi_sync_vc_vp(dsidev, channel); |
d6049144 | 2613 | case DSI_VC_SOURCE_L4: |
a72b64b9 | 2614 | return dsi_sync_vc_l4(dsidev, channel); |
cf398fb3 AT |
2615 | default: |
2616 | BUG(); | |
c6eee968 | 2617 | return -EINVAL; |
cf398fb3 AT |
2618 | } |
2619 | } | |
2620 | ||
a72b64b9 AT |
2621 | static int dsi_vc_enable(struct platform_device *dsidev, int channel, |
2622 | bool enable) | |
3de7a1dc | 2623 | { |
446f7bff TV |
2624 | DSSDBG("dsi_vc_enable channel %d, enable %d\n", |
2625 | channel, enable); | |
3de7a1dc TV |
2626 | |
2627 | enable = enable ? 1 : 0; | |
2628 | ||
a72b64b9 | 2629 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0); |
3de7a1dc | 2630 | |
a72b64b9 AT |
2631 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), |
2632 | 0, enable) != enable) { | |
3de7a1dc TV |
2633 | DSSERR("Failed to set dsi_vc_enable to %d\n", enable); |
2634 | return -EIO; | |
2635 | } | |
2636 | ||
2637 | return 0; | |
2638 | } | |
2639 | ||
a72b64b9 | 2640 | static void dsi_vc_initial_config(struct platform_device *dsidev, int channel) |
3de7a1dc | 2641 | { |
2c1a3ea0 | 2642 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
2643 | u32 r; |
2644 | ||
702d267e | 2645 | DSSDBG("Initial config of virtual channel %d", channel); |
3de7a1dc | 2646 | |
a72b64b9 | 2647 | r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); |
3de7a1dc TV |
2648 | |
2649 | if (FLD_GET(r, 15, 15)) /* VC_BUSY */ | |
2650 | DSSERR("VC(%d) busy when trying to configure it!\n", | |
2651 | channel); | |
2652 | ||
2653 | r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */ | |
2654 | r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */ | |
2655 | r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */ | |
2656 | r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */ | |
2657 | r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */ | |
2658 | r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */ | |
2659 | r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */ | |
9613c02b AT |
2660 | if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH)) |
2661 | r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */ | |
3de7a1dc TV |
2662 | |
2663 | r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */ | |
2664 | r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */ | |
2665 | ||
a72b64b9 | 2666 | dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r); |
2c1a3ea0 TV |
2667 | |
2668 | dsi->vc[channel].source = DSI_VC_SOURCE_L4; | |
3de7a1dc TV |
2669 | } |
2670 | ||
d6049144 AT |
2671 | static int dsi_vc_config_source(struct platform_device *dsidev, int channel, |
2672 | enum dsi_vc_source source) | |
3de7a1dc | 2673 | { |
f1da39d9 AT |
2674 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2675 | ||
d6049144 | 2676 | if (dsi->vc[channel].source == source) |
9ecd9684 | 2677 | return 0; |
3de7a1dc | 2678 | |
702d267e | 2679 | DSSDBG("Source config of virtual channel %d", channel); |
3de7a1dc | 2680 | |
a72b64b9 | 2681 | dsi_sync_vc(dsidev, channel); |
cf398fb3 | 2682 | |
a72b64b9 | 2683 | dsi_vc_enable(dsidev, channel, 0); |
3de7a1dc | 2684 | |
9ecd9684 | 2685 | /* VC_BUSY */ |
a72b64b9 | 2686 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) { |
3de7a1dc | 2687 | DSSERR("vc(%d) busy when trying to config for VP\n", channel); |
9ecd9684 TV |
2688 | return -EIO; |
2689 | } | |
3de7a1dc | 2690 | |
d6049144 AT |
2691 | /* SOURCE, 0 = L4, 1 = video port */ |
2692 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1); | |
3de7a1dc | 2693 | |
9613c02b | 2694 | /* DCS_CMD_ENABLE */ |
d6049144 AT |
2695 | if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { |
2696 | bool enable = source == DSI_VC_SOURCE_VP; | |
2697 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30); | |
2698 | } | |
9613c02b | 2699 | |
a72b64b9 | 2700 | dsi_vc_enable(dsidev, channel, 1); |
3de7a1dc | 2701 | |
d6049144 | 2702 | dsi->vc[channel].source = source; |
9ecd9684 TV |
2703 | |
2704 | return 0; | |
3de7a1dc TV |
2705 | } |
2706 | ||
1ffefe75 AT |
2707 | void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel, |
2708 | bool enable) | |
3de7a1dc | 2709 | { |
a72b64b9 | 2710 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
0b3ffe39 | 2711 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
a72b64b9 | 2712 | |
3de7a1dc TV |
2713 | DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable); |
2714 | ||
a72b64b9 | 2715 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
61140c9a | 2716 | |
a72b64b9 AT |
2717 | dsi_vc_enable(dsidev, channel, 0); |
2718 | dsi_if_enable(dsidev, 0); | |
3de7a1dc | 2719 | |
a72b64b9 | 2720 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9); |
3de7a1dc | 2721 | |
a72b64b9 AT |
2722 | dsi_vc_enable(dsidev, channel, 1); |
2723 | dsi_if_enable(dsidev, 1); | |
3de7a1dc | 2724 | |
a72b64b9 | 2725 | dsi_force_tx_stop_mode_io(dsidev); |
8af6ff01 AT |
2726 | |
2727 | /* start the DDR clock by sending a NULL packet */ | |
0b3ffe39 | 2728 | if (dsi->vm_timings.ddr_clk_always_on && enable) |
8af6ff01 | 2729 | dsi_vc_send_null(dssdev, channel); |
3de7a1dc | 2730 | } |
61140c9a | 2731 | EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs); |
3de7a1dc | 2732 | |
a72b64b9 | 2733 | static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel) |
3de7a1dc | 2734 | { |
a72b64b9 | 2735 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
3de7a1dc | 2736 | u32 val; |
a72b64b9 | 2737 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
3de7a1dc TV |
2738 | DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n", |
2739 | (val >> 0) & 0xff, | |
2740 | (val >> 8) & 0xff, | |
2741 | (val >> 16) & 0xff, | |
2742 | (val >> 24) & 0xff); | |
2743 | } | |
2744 | } | |
2745 | ||
2746 | static void dsi_show_rx_ack_with_err(u16 err) | |
2747 | { | |
2748 | DSSERR("\tACK with ERROR (%#x):\n", err); | |
2749 | if (err & (1 << 0)) | |
2750 | DSSERR("\t\tSoT Error\n"); | |
2751 | if (err & (1 << 1)) | |
2752 | DSSERR("\t\tSoT Sync Error\n"); | |
2753 | if (err & (1 << 2)) | |
2754 | DSSERR("\t\tEoT Sync Error\n"); | |
2755 | if (err & (1 << 3)) | |
2756 | DSSERR("\t\tEscape Mode Entry Command Error\n"); | |
2757 | if (err & (1 << 4)) | |
2758 | DSSERR("\t\tLP Transmit Sync Error\n"); | |
2759 | if (err & (1 << 5)) | |
2760 | DSSERR("\t\tHS Receive Timeout Error\n"); | |
2761 | if (err & (1 << 6)) | |
2762 | DSSERR("\t\tFalse Control Error\n"); | |
2763 | if (err & (1 << 7)) | |
2764 | DSSERR("\t\t(reserved7)\n"); | |
2765 | if (err & (1 << 8)) | |
2766 | DSSERR("\t\tECC Error, single-bit (corrected)\n"); | |
2767 | if (err & (1 << 9)) | |
2768 | DSSERR("\t\tECC Error, multi-bit (not corrected)\n"); | |
2769 | if (err & (1 << 10)) | |
2770 | DSSERR("\t\tChecksum Error\n"); | |
2771 | if (err & (1 << 11)) | |
2772 | DSSERR("\t\tData type not recognized\n"); | |
2773 | if (err & (1 << 12)) | |
2774 | DSSERR("\t\tInvalid VC ID\n"); | |
2775 | if (err & (1 << 13)) | |
2776 | DSSERR("\t\tInvalid Transmission Length\n"); | |
2777 | if (err & (1 << 14)) | |
2778 | DSSERR("\t\t(reserved14)\n"); | |
2779 | if (err & (1 << 15)) | |
2780 | DSSERR("\t\tDSI Protocol Violation\n"); | |
2781 | } | |
2782 | ||
a72b64b9 AT |
2783 | static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev, |
2784 | int channel) | |
3de7a1dc TV |
2785 | { |
2786 | /* RX_FIFO_NOT_EMPTY */ | |
a72b64b9 | 2787 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
3de7a1dc TV |
2788 | u32 val; |
2789 | u8 dt; | |
a72b64b9 | 2790 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
86a7867e | 2791 | DSSERR("\trawval %#08x\n", val); |
3de7a1dc | 2792 | dt = FLD_GET(val, 5, 0); |
7a7c48f9 | 2793 | if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { |
3de7a1dc TV |
2794 | u16 err = FLD_GET(val, 23, 8); |
2795 | dsi_show_rx_ack_with_err(err); | |
7a7c48f9 | 2796 | } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) { |
86a7867e | 2797 | DSSERR("\tDCS short response, 1 byte: %#x\n", |
3de7a1dc | 2798 | FLD_GET(val, 23, 8)); |
7a7c48f9 | 2799 | } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) { |
86a7867e | 2800 | DSSERR("\tDCS short response, 2 byte: %#x\n", |
3de7a1dc | 2801 | FLD_GET(val, 23, 8)); |
7a7c48f9 | 2802 | } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) { |
86a7867e | 2803 | DSSERR("\tDCS long response, len %d\n", |
3de7a1dc | 2804 | FLD_GET(val, 23, 8)); |
a72b64b9 | 2805 | dsi_vc_flush_long_data(dsidev, channel); |
3de7a1dc TV |
2806 | } else { |
2807 | DSSERR("\tunknown datatype 0x%02x\n", dt); | |
2808 | } | |
2809 | } | |
2810 | return 0; | |
2811 | } | |
2812 | ||
a72b64b9 | 2813 | static int dsi_vc_send_bta(struct platform_device *dsidev, int channel) |
3de7a1dc | 2814 | { |
f1da39d9 AT |
2815 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
2816 | ||
2817 | if (dsi->debug_write || dsi->debug_read) | |
3de7a1dc TV |
2818 | DSSDBG("dsi_vc_send_bta %d\n", channel); |
2819 | ||
a72b64b9 | 2820 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
3de7a1dc | 2821 | |
a72b64b9 AT |
2822 | /* RX_FIFO_NOT_EMPTY */ |
2823 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { | |
3de7a1dc | 2824 | DSSERR("rx fifo not empty when sending BTA, dumping data:\n"); |
a72b64b9 | 2825 | dsi_vc_flush_receive_data(dsidev, channel); |
3de7a1dc TV |
2826 | } |
2827 | ||
a72b64b9 | 2828 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */ |
3de7a1dc | 2829 | |
968f8e97 TV |
2830 | /* flush posted write */ |
2831 | dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); | |
2832 | ||
3de7a1dc TV |
2833 | return 0; |
2834 | } | |
2835 | ||
1ffefe75 | 2836 | int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel) |
3de7a1dc | 2837 | { |
a72b64b9 | 2838 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
f36a06e7 | 2839 | DECLARE_COMPLETION_ONSTACK(completion); |
3de7a1dc TV |
2840 | int r = 0; |
2841 | u32 err; | |
2842 | ||
a72b64b9 | 2843 | r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler, |
f36a06e7 TV |
2844 | &completion, DSI_VC_IRQ_BTA); |
2845 | if (r) | |
2846 | goto err0; | |
3de7a1dc | 2847 | |
a72b64b9 | 2848 | r = dsi_register_isr(dsidev, dsi_completion_handler, &completion, |
773b30b2 | 2849 | DSI_IRQ_ERROR_MASK); |
3de7a1dc | 2850 | if (r) |
f36a06e7 | 2851 | goto err1; |
3de7a1dc | 2852 | |
a72b64b9 | 2853 | r = dsi_vc_send_bta(dsidev, channel); |
773b30b2 TV |
2854 | if (r) |
2855 | goto err2; | |
2856 | ||
f36a06e7 | 2857 | if (wait_for_completion_timeout(&completion, |
3de7a1dc TV |
2858 | msecs_to_jiffies(500)) == 0) { |
2859 | DSSERR("Failed to receive BTA\n"); | |
2860 | r = -EIO; | |
773b30b2 | 2861 | goto err2; |
3de7a1dc TV |
2862 | } |
2863 | ||
a72b64b9 | 2864 | err = dsi_get_errors(dsidev); |
3de7a1dc TV |
2865 | if (err) { |
2866 | DSSERR("Error while sending BTA: %x\n", err); | |
2867 | r = -EIO; | |
773b30b2 | 2868 | goto err2; |
3de7a1dc | 2869 | } |
773b30b2 | 2870 | err2: |
a72b64b9 | 2871 | dsi_unregister_isr(dsidev, dsi_completion_handler, &completion, |
773b30b2 | 2872 | DSI_IRQ_ERROR_MASK); |
f36a06e7 | 2873 | err1: |
a72b64b9 | 2874 | dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler, |
f36a06e7 TV |
2875 | &completion, DSI_VC_IRQ_BTA); |
2876 | err0: | |
3de7a1dc TV |
2877 | return r; |
2878 | } | |
2879 | EXPORT_SYMBOL(dsi_vc_send_bta_sync); | |
2880 | ||
a72b64b9 AT |
2881 | static inline void dsi_vc_write_long_header(struct platform_device *dsidev, |
2882 | int channel, u8 data_type, u16 len, u8 ecc) | |
3de7a1dc | 2883 | { |
f1da39d9 | 2884 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
2885 | u32 val; |
2886 | u8 data_id; | |
2887 | ||
a72b64b9 | 2888 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
3de7a1dc | 2889 | |
f1da39d9 | 2890 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
3de7a1dc TV |
2891 | |
2892 | val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) | | |
2893 | FLD_VAL(ecc, 31, 24); | |
2894 | ||
a72b64b9 | 2895 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val); |
3de7a1dc TV |
2896 | } |
2897 | ||
a72b64b9 AT |
2898 | static inline void dsi_vc_write_long_payload(struct platform_device *dsidev, |
2899 | int channel, u8 b1, u8 b2, u8 b3, u8 b4) | |
3de7a1dc TV |
2900 | { |
2901 | u32 val; | |
2902 | ||
2903 | val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0; | |
2904 | ||
2905 | /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n", | |
2906 | b1, b2, b3, b4, val); */ | |
2907 | ||
a72b64b9 | 2908 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val); |
3de7a1dc TV |
2909 | } |
2910 | ||
a72b64b9 AT |
2911 | static int dsi_vc_send_long(struct platform_device *dsidev, int channel, |
2912 | u8 data_type, u8 *data, u16 len, u8 ecc) | |
3de7a1dc TV |
2913 | { |
2914 | /*u32 val; */ | |
f1da39d9 | 2915 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
2916 | int i; |
2917 | u8 *p; | |
2918 | int r = 0; | |
2919 | u8 b1, b2, b3, b4; | |
2920 | ||
f1da39d9 | 2921 | if (dsi->debug_write) |
3de7a1dc TV |
2922 | DSSDBG("dsi_vc_send_long, %d bytes\n", len); |
2923 | ||
2924 | /* len + header */ | |
f1da39d9 | 2925 | if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) { |
3de7a1dc TV |
2926 | DSSERR("unable to send long packet: packet too long.\n"); |
2927 | return -EINVAL; | |
2928 | } | |
2929 | ||
d6049144 | 2930 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); |
3de7a1dc | 2931 | |
a72b64b9 | 2932 | dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc); |
3de7a1dc | 2933 | |
3de7a1dc TV |
2934 | p = data; |
2935 | for (i = 0; i < len >> 2; i++) { | |
f1da39d9 | 2936 | if (dsi->debug_write) |
3de7a1dc | 2937 | DSSDBG("\tsending full packet %d\n", i); |
3de7a1dc TV |
2938 | |
2939 | b1 = *p++; | |
2940 | b2 = *p++; | |
2941 | b3 = *p++; | |
2942 | b4 = *p++; | |
2943 | ||
a72b64b9 | 2944 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4); |
3de7a1dc TV |
2945 | } |
2946 | ||
2947 | i = len % 4; | |
2948 | if (i) { | |
2949 | b1 = 0; b2 = 0; b3 = 0; | |
2950 | ||
f1da39d9 | 2951 | if (dsi->debug_write) |
3de7a1dc TV |
2952 | DSSDBG("\tsending remainder bytes %d\n", i); |
2953 | ||
2954 | switch (i) { | |
2955 | case 3: | |
2956 | b1 = *p++; | |
2957 | b2 = *p++; | |
2958 | b3 = *p++; | |
2959 | break; | |
2960 | case 2: | |
2961 | b1 = *p++; | |
2962 | b2 = *p++; | |
2963 | break; | |
2964 | case 1: | |
2965 | b1 = *p++; | |
2966 | break; | |
2967 | } | |
2968 | ||
a72b64b9 | 2969 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0); |
3de7a1dc TV |
2970 | } |
2971 | ||
2972 | return r; | |
2973 | } | |
2974 | ||
a72b64b9 AT |
2975 | static int dsi_vc_send_short(struct platform_device *dsidev, int channel, |
2976 | u8 data_type, u16 data, u8 ecc) | |
3de7a1dc | 2977 | { |
f1da39d9 | 2978 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
2979 | u32 r; |
2980 | u8 data_id; | |
2981 | ||
a72b64b9 | 2982 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
3de7a1dc | 2983 | |
f1da39d9 | 2984 | if (dsi->debug_write) |
3de7a1dc TV |
2985 | DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n", |
2986 | channel, | |
2987 | data_type, data & 0xff, (data >> 8) & 0xff); | |
2988 | ||
d6049144 | 2989 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); |
3de7a1dc | 2990 | |
a72b64b9 | 2991 | if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) { |
3de7a1dc TV |
2992 | DSSERR("ERROR FIFO FULL, aborting transfer\n"); |
2993 | return -EINVAL; | |
2994 | } | |
2995 | ||
f1da39d9 | 2996 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
3de7a1dc TV |
2997 | |
2998 | r = (data_id << 0) | (data << 8) | (ecc << 24); | |
2999 | ||
a72b64b9 | 3000 | dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r); |
3de7a1dc TV |
3001 | |
3002 | return 0; | |
3003 | } | |
3004 | ||
1ffefe75 | 3005 | int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel) |
3de7a1dc | 3006 | { |
a72b64b9 | 3007 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
a72b64b9 | 3008 | |
18b7d099 AT |
3009 | return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL, |
3010 | 0, 0); | |
3de7a1dc TV |
3011 | } |
3012 | EXPORT_SYMBOL(dsi_vc_send_null); | |
3013 | ||
9e7e9372 | 3014 | static int dsi_vc_write_nosync_common(struct platform_device *dsidev, |
6ff8aa31 | 3015 | int channel, u8 *data, int len, enum dss_dsi_content_type type) |
3de7a1dc TV |
3016 | { |
3017 | int r; | |
3018 | ||
6ff8aa31 AT |
3019 | if (len == 0) { |
3020 | BUG_ON(type == DSS_DSI_CONTENT_DCS); | |
7a7c48f9 | 3021 | r = dsi_vc_send_short(dsidev, channel, |
6ff8aa31 AT |
3022 | MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0); |
3023 | } else if (len == 1) { | |
3024 | r = dsi_vc_send_short(dsidev, channel, | |
3025 | type == DSS_DSI_CONTENT_GENERIC ? | |
3026 | MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM : | |
7a7c48f9 | 3027 | MIPI_DSI_DCS_SHORT_WRITE, data[0], 0); |
3de7a1dc | 3028 | } else if (len == 2) { |
7a7c48f9 | 3029 | r = dsi_vc_send_short(dsidev, channel, |
6ff8aa31 AT |
3030 | type == DSS_DSI_CONTENT_GENERIC ? |
3031 | MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM : | |
7a7c48f9 | 3032 | MIPI_DSI_DCS_SHORT_WRITE_PARAM, |
3de7a1dc TV |
3033 | data[0] | (data[1] << 8), 0); |
3034 | } else { | |
6ff8aa31 AT |
3035 | r = dsi_vc_send_long(dsidev, channel, |
3036 | type == DSS_DSI_CONTENT_GENERIC ? | |
3037 | MIPI_DSI_GENERIC_LONG_WRITE : | |
3038 | MIPI_DSI_DCS_LONG_WRITE, data, len, 0); | |
3de7a1dc TV |
3039 | } |
3040 | ||
3041 | return r; | |
3042 | } | |
6ff8aa31 AT |
3043 | |
3044 | int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel, | |
3045 | u8 *data, int len) | |
3046 | { | |
9e7e9372 AT |
3047 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
3048 | ||
3049 | return dsi_vc_write_nosync_common(dsidev, channel, data, len, | |
6ff8aa31 AT |
3050 | DSS_DSI_CONTENT_DCS); |
3051 | } | |
3de7a1dc TV |
3052 | EXPORT_SYMBOL(dsi_vc_dcs_write_nosync); |
3053 | ||
6ff8aa31 AT |
3054 | int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel, |
3055 | u8 *data, int len) | |
3056 | { | |
9e7e9372 AT |
3057 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
3058 | ||
3059 | return dsi_vc_write_nosync_common(dsidev, channel, data, len, | |
6ff8aa31 AT |
3060 | DSS_DSI_CONTENT_GENERIC); |
3061 | } | |
3062 | EXPORT_SYMBOL(dsi_vc_generic_write_nosync); | |
3063 | ||
3064 | static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel, | |
3065 | u8 *data, int len, enum dss_dsi_content_type type) | |
3de7a1dc | 3066 | { |
a72b64b9 | 3067 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
3de7a1dc TV |
3068 | int r; |
3069 | ||
9e7e9372 | 3070 | r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type); |
3de7a1dc | 3071 | if (r) |
5d68e032 | 3072 | goto err; |
3de7a1dc | 3073 | |
1ffefe75 | 3074 | r = dsi_vc_send_bta_sync(dssdev, channel); |
5d68e032 TV |
3075 | if (r) |
3076 | goto err; | |
3de7a1dc | 3077 | |
a72b64b9 AT |
3078 | /* RX_FIFO_NOT_EMPTY */ |
3079 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { | |
b63ac1e3 | 3080 | DSSERR("rx fifo not empty after write, dumping data:\n"); |
a72b64b9 | 3081 | dsi_vc_flush_receive_data(dsidev, channel); |
b63ac1e3 TV |
3082 | r = -EIO; |
3083 | goto err; | |
3084 | } | |
3085 | ||
5d68e032 TV |
3086 | return 0; |
3087 | err: | |
6ff8aa31 | 3088 | DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n", |
5d68e032 | 3089 | channel, data[0], len); |
3de7a1dc TV |
3090 | return r; |
3091 | } | |
6ff8aa31 AT |
3092 | |
3093 | int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data, | |
3094 | int len) | |
3095 | { | |
3096 | return dsi_vc_write_common(dssdev, channel, data, len, | |
3097 | DSS_DSI_CONTENT_DCS); | |
3098 | } | |
3de7a1dc TV |
3099 | EXPORT_SYMBOL(dsi_vc_dcs_write); |
3100 | ||
6ff8aa31 AT |
3101 | int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data, |
3102 | int len) | |
3103 | { | |
3104 | return dsi_vc_write_common(dssdev, channel, data, len, | |
3105 | DSS_DSI_CONTENT_GENERIC); | |
3106 | } | |
3107 | EXPORT_SYMBOL(dsi_vc_generic_write); | |
3108 | ||
1ffefe75 | 3109 | int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd) |
828c48f8 | 3110 | { |
1ffefe75 | 3111 | return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1); |
828c48f8 TV |
3112 | } |
3113 | EXPORT_SYMBOL(dsi_vc_dcs_write_0); | |
3114 | ||
6ff8aa31 AT |
3115 | int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel) |
3116 | { | |
3117 | return dsi_vc_generic_write(dssdev, channel, NULL, 0); | |
3118 | } | |
3119 | EXPORT_SYMBOL(dsi_vc_generic_write_0); | |
3120 | ||
1ffefe75 AT |
3121 | int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
3122 | u8 param) | |
828c48f8 TV |
3123 | { |
3124 | u8 buf[2]; | |
3125 | buf[0] = dcs_cmd; | |
3126 | buf[1] = param; | |
1ffefe75 | 3127 | return dsi_vc_dcs_write(dssdev, channel, buf, 2); |
828c48f8 TV |
3128 | } |
3129 | EXPORT_SYMBOL(dsi_vc_dcs_write_1); | |
3130 | ||
6ff8aa31 AT |
3131 | int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel, |
3132 | u8 param) | |
3133 | { | |
3134 | return dsi_vc_generic_write(dssdev, channel, ¶m, 1); | |
3135 | } | |
3136 | EXPORT_SYMBOL(dsi_vc_generic_write_1); | |
3137 | ||
3138 | int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel, | |
3139 | u8 param1, u8 param2) | |
3140 | { | |
3141 | u8 buf[2]; | |
3142 | buf[0] = param1; | |
3143 | buf[1] = param2; | |
3144 | return dsi_vc_generic_write(dssdev, channel, buf, 2); | |
3145 | } | |
3146 | EXPORT_SYMBOL(dsi_vc_generic_write_2); | |
3147 | ||
9e7e9372 | 3148 | static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev, |
b850975c | 3149 | int channel, u8 dcs_cmd) |
3de7a1dc | 3150 | { |
f1da39d9 | 3151 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
3152 | int r; |
3153 | ||
f1da39d9 | 3154 | if (dsi->debug_read) |
b850975c AT |
3155 | DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n", |
3156 | channel, dcs_cmd); | |
3de7a1dc | 3157 | |
7a7c48f9 | 3158 | r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0); |
b850975c AT |
3159 | if (r) { |
3160 | DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)" | |
3161 | " failed\n", channel, dcs_cmd); | |
3162 | return r; | |
3163 | } | |
3de7a1dc | 3164 | |
b850975c AT |
3165 | return 0; |
3166 | } | |
3167 | ||
9e7e9372 | 3168 | static int dsi_vc_generic_send_read_request(struct platform_device *dsidev, |
b3b89c05 AT |
3169 | int channel, u8 *reqdata, int reqlen) |
3170 | { | |
b3b89c05 AT |
3171 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3172 | u16 data; | |
3173 | u8 data_type; | |
3174 | int r; | |
3175 | ||
3176 | if (dsi->debug_read) | |
3177 | DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n", | |
3178 | channel, reqlen); | |
3179 | ||
3180 | if (reqlen == 0) { | |
3181 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM; | |
3182 | data = 0; | |
3183 | } else if (reqlen == 1) { | |
3184 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM; | |
3185 | data = reqdata[0]; | |
3186 | } else if (reqlen == 2) { | |
3187 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM; | |
3188 | data = reqdata[0] | (reqdata[1] << 8); | |
3189 | } else { | |
3190 | BUG(); | |
c6eee968 | 3191 | return -EINVAL; |
b3b89c05 AT |
3192 | } |
3193 | ||
3194 | r = dsi_vc_send_short(dsidev, channel, data_type, data, 0); | |
3195 | if (r) { | |
3196 | DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)" | |
3197 | " failed\n", channel, reqlen); | |
3198 | return r; | |
3199 | } | |
3200 | ||
3201 | return 0; | |
3202 | } | |
3203 | ||
3204 | static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel, | |
3205 | u8 *buf, int buflen, enum dss_dsi_content_type type) | |
b850975c AT |
3206 | { |
3207 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
3208 | u32 val; | |
3209 | u8 dt; | |
3210 | int r; | |
3de7a1dc TV |
3211 | |
3212 | /* RX_FIFO_NOT_EMPTY */ | |
a72b64b9 | 3213 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) { |
3de7a1dc | 3214 | DSSERR("RX fifo empty when trying to read.\n"); |
5d68e032 TV |
3215 | r = -EIO; |
3216 | goto err; | |
3de7a1dc TV |
3217 | } |
3218 | ||
a72b64b9 | 3219 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
f1da39d9 | 3220 | if (dsi->debug_read) |
3de7a1dc TV |
3221 | DSSDBG("\theader: %08x\n", val); |
3222 | dt = FLD_GET(val, 5, 0); | |
7a7c48f9 | 3223 | if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { |
3de7a1dc TV |
3224 | u16 err = FLD_GET(val, 23, 8); |
3225 | dsi_show_rx_ack_with_err(err); | |
5d68e032 TV |
3226 | r = -EIO; |
3227 | goto err; | |
3de7a1dc | 3228 | |
b3b89c05 AT |
3229 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
3230 | MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE : | |
3231 | MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) { | |
3de7a1dc | 3232 | u8 data = FLD_GET(val, 15, 8); |
f1da39d9 | 3233 | if (dsi->debug_read) |
b3b89c05 AT |
3234 | DSSDBG("\t%s short response, 1 byte: %02x\n", |
3235 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : | |
3236 | "DCS", data); | |
3de7a1dc | 3237 | |
5d68e032 TV |
3238 | if (buflen < 1) { |
3239 | r = -EIO; | |
3240 | goto err; | |
3241 | } | |
3de7a1dc TV |
3242 | |
3243 | buf[0] = data; | |
3244 | ||
3245 | return 1; | |
b3b89c05 AT |
3246 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
3247 | MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE : | |
3248 | MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) { | |
3de7a1dc | 3249 | u16 data = FLD_GET(val, 23, 8); |
f1da39d9 | 3250 | if (dsi->debug_read) |
b3b89c05 AT |
3251 | DSSDBG("\t%s short response, 2 byte: %04x\n", |
3252 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : | |
3253 | "DCS", data); | |
3de7a1dc | 3254 | |
5d68e032 TV |
3255 | if (buflen < 2) { |
3256 | r = -EIO; | |
3257 | goto err; | |
3258 | } | |
3de7a1dc TV |
3259 | |
3260 | buf[0] = data & 0xff; | |
3261 | buf[1] = (data >> 8) & 0xff; | |
3262 | ||
3263 | return 2; | |
b3b89c05 AT |
3264 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
3265 | MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE : | |
3266 | MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) { | |
3de7a1dc TV |
3267 | int w; |
3268 | int len = FLD_GET(val, 23, 8); | |
f1da39d9 | 3269 | if (dsi->debug_read) |
b3b89c05 AT |
3270 | DSSDBG("\t%s long response, len %d\n", |
3271 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : | |
3272 | "DCS", len); | |
3de7a1dc | 3273 | |
5d68e032 TV |
3274 | if (len > buflen) { |
3275 | r = -EIO; | |
3276 | goto err; | |
3277 | } | |
3de7a1dc TV |
3278 | |
3279 | /* two byte checksum ends the packet, not included in len */ | |
3280 | for (w = 0; w < len + 2;) { | |
3281 | int b; | |
a72b64b9 AT |
3282 | val = dsi_read_reg(dsidev, |
3283 | DSI_VC_SHORT_PACKET_HEADER(channel)); | |
f1da39d9 | 3284 | if (dsi->debug_read) |
3de7a1dc TV |
3285 | DSSDBG("\t\t%02x %02x %02x %02x\n", |
3286 | (val >> 0) & 0xff, | |
3287 | (val >> 8) & 0xff, | |
3288 | (val >> 16) & 0xff, | |
3289 | (val >> 24) & 0xff); | |
3290 | ||
3291 | for (b = 0; b < 4; ++b) { | |
3292 | if (w < len) | |
3293 | buf[w] = (val >> (b * 8)) & 0xff; | |
3294 | /* we discard the 2 byte checksum */ | |
3295 | ++w; | |
3296 | } | |
3297 | } | |
3298 | ||
3299 | return len; | |
3de7a1dc TV |
3300 | } else { |
3301 | DSSERR("\tunknown datatype 0x%02x\n", dt); | |
5d68e032 TV |
3302 | r = -EIO; |
3303 | goto err; | |
3de7a1dc | 3304 | } |
5d68e032 | 3305 | |
5d68e032 | 3306 | err: |
b3b89c05 AT |
3307 | DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel, |
3308 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS"); | |
b850975c | 3309 | |
5d68e032 | 3310 | return r; |
b850975c AT |
3311 | } |
3312 | ||
3313 | int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, | |
3314 | u8 *buf, int buflen) | |
3315 | { | |
3316 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); | |
3317 | int r; | |
3318 | ||
9e7e9372 | 3319 | r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd); |
b850975c AT |
3320 | if (r) |
3321 | goto err; | |
5d68e032 | 3322 | |
b850975c AT |
3323 | r = dsi_vc_send_bta_sync(dssdev, channel); |
3324 | if (r) | |
3325 | goto err; | |
3326 | ||
b3b89c05 AT |
3327 | r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen, |
3328 | DSS_DSI_CONTENT_DCS); | |
b850975c AT |
3329 | if (r < 0) |
3330 | goto err; | |
3331 | ||
3332 | if (r != buflen) { | |
3333 | r = -EIO; | |
3334 | goto err; | |
3335 | } | |
3336 | ||
3337 | return 0; | |
3338 | err: | |
3339 | DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd); | |
3340 | return r; | |
3de7a1dc TV |
3341 | } |
3342 | EXPORT_SYMBOL(dsi_vc_dcs_read); | |
3343 | ||
b3b89c05 AT |
3344 | static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel, |
3345 | u8 *reqdata, int reqlen, u8 *buf, int buflen) | |
3346 | { | |
3347 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); | |
3348 | int r; | |
3349 | ||
9e7e9372 | 3350 | r = dsi_vc_generic_send_read_request(dsidev, channel, reqdata, reqlen); |
b3b89c05 AT |
3351 | if (r) |
3352 | return r; | |
3353 | ||
3354 | r = dsi_vc_send_bta_sync(dssdev, channel); | |
3355 | if (r) | |
3356 | return r; | |
3357 | ||
3358 | r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen, | |
3359 | DSS_DSI_CONTENT_GENERIC); | |
3360 | if (r < 0) | |
3361 | return r; | |
3362 | ||
3363 | if (r != buflen) { | |
3364 | r = -EIO; | |
3365 | return r; | |
3366 | } | |
3367 | ||
3368 | return 0; | |
3369 | } | |
3370 | ||
3371 | int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf, | |
3372 | int buflen) | |
3373 | { | |
3374 | int r; | |
3375 | ||
3376 | r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen); | |
3377 | if (r) { | |
3378 | DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel); | |
3379 | return r; | |
3380 | } | |
3381 | ||
3382 | return 0; | |
3383 | } | |
3384 | EXPORT_SYMBOL(dsi_vc_generic_read_0); | |
3385 | ||
3386 | int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param, | |
3387 | u8 *buf, int buflen) | |
3388 | { | |
3389 | int r; | |
3390 | ||
3391 | r = dsi_vc_generic_read(dssdev, channel, ¶m, 1, buf, buflen); | |
3392 | if (r) { | |
3393 | DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel); | |
3394 | return r; | |
3395 | } | |
3396 | ||
3397 | return 0; | |
3398 | } | |
3399 | EXPORT_SYMBOL(dsi_vc_generic_read_1); | |
3400 | ||
3401 | int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel, | |
3402 | u8 param1, u8 param2, u8 *buf, int buflen) | |
3403 | { | |
3404 | int r; | |
3405 | u8 reqdata[2]; | |
3406 | ||
3407 | reqdata[0] = param1; | |
3408 | reqdata[1] = param2; | |
3409 | ||
3410 | r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen); | |
3411 | if (r) { | |
3412 | DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel); | |
3413 | return r; | |
3414 | } | |
3415 | ||
3416 | return 0; | |
3417 | } | |
3418 | EXPORT_SYMBOL(dsi_vc_generic_read_2); | |
3419 | ||
1ffefe75 AT |
3420 | int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel, |
3421 | u16 len) | |
3de7a1dc | 3422 | { |
a72b64b9 AT |
3423 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
3424 | ||
7a7c48f9 AT |
3425 | return dsi_vc_send_short(dsidev, channel, |
3426 | MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0); | |
3de7a1dc TV |
3427 | } |
3428 | EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size); | |
3429 | ||
a72b64b9 | 3430 | static int dsi_enter_ulps(struct platform_device *dsidev) |
40885ab3 | 3431 | { |
f1da39d9 | 3432 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
40885ab3 | 3433 | DECLARE_COMPLETION_ONSTACK(completion); |
522a0c2f TV |
3434 | int r, i; |
3435 | unsigned mask; | |
40885ab3 | 3436 | |
702d267e | 3437 | DSSDBG("Entering ULPS"); |
40885ab3 | 3438 | |
a72b64b9 | 3439 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
40885ab3 | 3440 | |
f1da39d9 | 3441 | WARN_ON(dsi->ulps_enabled); |
40885ab3 | 3442 | |
f1da39d9 | 3443 | if (dsi->ulps_enabled) |
40885ab3 TV |
3444 | return 0; |
3445 | ||
6cc78aa9 | 3446 | /* DDR_CLK_ALWAYS_ON */ |
a72b64b9 | 3447 | if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) { |
6cc78aa9 TV |
3448 | dsi_if_enable(dsidev, 0); |
3449 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); | |
3450 | dsi_if_enable(dsidev, 1); | |
40885ab3 TV |
3451 | } |
3452 | ||
a72b64b9 AT |
3453 | dsi_sync_vc(dsidev, 0); |
3454 | dsi_sync_vc(dsidev, 1); | |
3455 | dsi_sync_vc(dsidev, 2); | |
3456 | dsi_sync_vc(dsidev, 3); | |
40885ab3 | 3457 | |
a72b64b9 | 3458 | dsi_force_tx_stop_mode_io(dsidev); |
40885ab3 | 3459 | |
a72b64b9 AT |
3460 | dsi_vc_enable(dsidev, 0, false); |
3461 | dsi_vc_enable(dsidev, 1, false); | |
3462 | dsi_vc_enable(dsidev, 2, false); | |
3463 | dsi_vc_enable(dsidev, 3, false); | |
40885ab3 | 3464 | |
a72b64b9 | 3465 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */ |
40885ab3 TV |
3466 | DSSERR("HS busy when enabling ULPS\n"); |
3467 | return -EIO; | |
3468 | } | |
3469 | ||
a72b64b9 | 3470 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */ |
40885ab3 TV |
3471 | DSSERR("LP busy when enabling ULPS\n"); |
3472 | return -EIO; | |
3473 | } | |
3474 | ||
a72b64b9 | 3475 | r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion, |
40885ab3 TV |
3476 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
3477 | if (r) | |
3478 | return r; | |
3479 | ||
522a0c2f TV |
3480 | mask = 0; |
3481 | ||
3482 | for (i = 0; i < dsi->num_lanes_supported; ++i) { | |
3483 | if (dsi->lanes[i].function == DSI_LANE_UNUSED) | |
3484 | continue; | |
3485 | mask |= 1 << i; | |
3486 | } | |
40885ab3 TV |
3487 | /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */ |
3488 | /* LANEx_ULPS_SIG2 */ | |
522a0c2f | 3489 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5); |
40885ab3 | 3490 | |
a702c859 TV |
3491 | /* flush posted write and wait for SCP interface to finish the write */ |
3492 | dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); | |
40885ab3 TV |
3493 | |
3494 | if (wait_for_completion_timeout(&completion, | |
3495 | msecs_to_jiffies(1000)) == 0) { | |
3496 | DSSERR("ULPS enable timeout\n"); | |
3497 | r = -EIO; | |
3498 | goto err; | |
3499 | } | |
3500 | ||
a72b64b9 | 3501 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
40885ab3 TV |
3502 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
3503 | ||
8ef0e614 | 3504 | /* Reset LANEx_ULPS_SIG2 */ |
522a0c2f | 3505 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5); |
8ef0e614 | 3506 | |
a702c859 TV |
3507 | /* flush posted write and wait for SCP interface to finish the write */ |
3508 | dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); | |
8ef0e614 | 3509 | |
a72b64b9 | 3510 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS); |
40885ab3 | 3511 | |
a72b64b9 | 3512 | dsi_if_enable(dsidev, false); |
40885ab3 | 3513 | |
f1da39d9 | 3514 | dsi->ulps_enabled = true; |
40885ab3 TV |
3515 | |
3516 | return 0; | |
3517 | ||
3518 | err: | |
a72b64b9 | 3519 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
40885ab3 TV |
3520 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
3521 | return r; | |
3522 | } | |
3523 | ||
a72b64b9 AT |
3524 | static void dsi_set_lp_rx_timeout(struct platform_device *dsidev, |
3525 | unsigned ticks, bool x4, bool x16) | |
3de7a1dc | 3526 | { |
3de7a1dc | 3527 | unsigned long fck; |
4ffa3571 TV |
3528 | unsigned long total_ticks; |
3529 | u32 r; | |
3de7a1dc | 3530 | |
4ffa3571 | 3531 | BUG_ON(ticks > 0x1fff); |
3de7a1dc | 3532 | |
4ffa3571 | 3533 | /* ticks in DSI_FCK */ |
a72b64b9 | 3534 | fck = dsi_fclk_rate(dsidev); |
3de7a1dc | 3535 | |
a72b64b9 | 3536 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
3de7a1dc | 3537 | r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */ |
4ffa3571 TV |
3538 | r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */ |
3539 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */ | |
3de7a1dc | 3540 | r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */ |
a72b64b9 | 3541 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
3de7a1dc | 3542 | |
4ffa3571 TV |
3543 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
3544 | ||
3545 | DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n", | |
3546 | total_ticks, | |
3547 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", | |
3548 | (total_ticks * 1000) / (fck / 1000 / 1000)); | |
3de7a1dc TV |
3549 | } |
3550 | ||
a72b64b9 AT |
3551 | static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks, |
3552 | bool x8, bool x16) | |
3de7a1dc | 3553 | { |
3de7a1dc | 3554 | unsigned long fck; |
4ffa3571 TV |
3555 | unsigned long total_ticks; |
3556 | u32 r; | |
3557 | ||
3558 | BUG_ON(ticks > 0x1fff); | |
3de7a1dc TV |
3559 | |
3560 | /* ticks in DSI_FCK */ | |
a72b64b9 | 3561 | fck = dsi_fclk_rate(dsidev); |
3de7a1dc | 3562 | |
a72b64b9 | 3563 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
3de7a1dc | 3564 | r = FLD_MOD(r, 1, 31, 31); /* TA_TO */ |
4ffa3571 TV |
3565 | r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */ |
3566 | r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */ | |
3de7a1dc | 3567 | r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */ |
a72b64b9 | 3568 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
3de7a1dc | 3569 | |
4ffa3571 TV |
3570 | total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1); |
3571 | ||
3572 | DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n", | |
3573 | total_ticks, | |
3574 | ticks, x8 ? " x8" : "", x16 ? " x16" : "", | |
3575 | (total_ticks * 1000) / (fck / 1000 / 1000)); | |
3de7a1dc TV |
3576 | } |
3577 | ||
a72b64b9 AT |
3578 | static void dsi_set_stop_state_counter(struct platform_device *dsidev, |
3579 | unsigned ticks, bool x4, bool x16) | |
3de7a1dc | 3580 | { |
3de7a1dc | 3581 | unsigned long fck; |
4ffa3571 TV |
3582 | unsigned long total_ticks; |
3583 | u32 r; | |
3de7a1dc | 3584 | |
4ffa3571 | 3585 | BUG_ON(ticks > 0x1fff); |
3de7a1dc | 3586 | |
4ffa3571 | 3587 | /* ticks in DSI_FCK */ |
a72b64b9 | 3588 | fck = dsi_fclk_rate(dsidev); |
3de7a1dc | 3589 | |
a72b64b9 | 3590 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
3de7a1dc | 3591 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
4ffa3571 TV |
3592 | r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */ |
3593 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */ | |
3de7a1dc | 3594 | r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */ |
a72b64b9 | 3595 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
3de7a1dc | 3596 | |
4ffa3571 TV |
3597 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
3598 | ||
3599 | DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n", | |
3600 | total_ticks, | |
3601 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", | |
3602 | (total_ticks * 1000) / (fck / 1000 / 1000)); | |
3de7a1dc TV |
3603 | } |
3604 | ||
a72b64b9 AT |
3605 | static void dsi_set_hs_tx_timeout(struct platform_device *dsidev, |
3606 | unsigned ticks, bool x4, bool x16) | |
3de7a1dc | 3607 | { |
3de7a1dc | 3608 | unsigned long fck; |
4ffa3571 TV |
3609 | unsigned long total_ticks; |
3610 | u32 r; | |
3de7a1dc | 3611 | |
4ffa3571 | 3612 | BUG_ON(ticks > 0x1fff); |
3de7a1dc | 3613 | |
4ffa3571 | 3614 | /* ticks in TxByteClkHS */ |
a72b64b9 | 3615 | fck = dsi_get_txbyteclkhs(dsidev); |
3de7a1dc | 3616 | |
a72b64b9 | 3617 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
3de7a1dc | 3618 | r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */ |
4ffa3571 TV |
3619 | r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */ |
3620 | r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */ | |
3de7a1dc | 3621 | r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */ |
a72b64b9 | 3622 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
3de7a1dc | 3623 | |
4ffa3571 TV |
3624 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
3625 | ||
3626 | DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n", | |
3627 | total_ticks, | |
3628 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", | |
3629 | (total_ticks * 1000) / (fck / 1000 / 1000)); | |
3de7a1dc | 3630 | } |
8af6ff01 | 3631 | |
9e7e9372 | 3632 | static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev) |
8af6ff01 | 3633 | { |
dca2b152 | 3634 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
8af6ff01 AT |
3635 | int num_line_buffers; |
3636 | ||
dca2b152 | 3637 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
02c3960b | 3638 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
e67458a8 | 3639 | struct omap_video_timings *timings = &dsi->timings; |
8af6ff01 AT |
3640 | /* |
3641 | * Don't use line buffers if width is greater than the video | |
3642 | * port's line buffer size | |
3643 | */ | |
99322577 | 3644 | if (dsi->line_buffer_size <= timings->x_res * bpp / 8) |
8af6ff01 AT |
3645 | num_line_buffers = 0; |
3646 | else | |
3647 | num_line_buffers = 2; | |
3648 | } else { | |
3649 | /* Use maximum number of line buffers in command mode */ | |
3650 | num_line_buffers = 2; | |
3651 | } | |
3652 | ||
3653 | /* LINE_BUFFER */ | |
3654 | REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12); | |
3655 | } | |
3656 | ||
9e7e9372 | 3657 | static void dsi_config_vp_sync_events(struct platform_device *dsidev) |
8af6ff01 | 3658 | { |
0b3ffe39 | 3659 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
478d7df8 | 3660 | bool sync_end; |
8af6ff01 AT |
3661 | u32 r; |
3662 | ||
478d7df8 TV |
3663 | if (dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE) |
3664 | sync_end = true; | |
3665 | else | |
3666 | sync_end = false; | |
3667 | ||
8af6ff01 | 3668 | r = dsi_read_reg(dsidev, DSI_CTRL); |
bd5a7b11 AT |
3669 | r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */ |
3670 | r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */ | |
3671 | r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */ | |
8af6ff01 | 3672 | r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */ |
478d7df8 | 3673 | r = FLD_MOD(r, sync_end, 16, 16); /* VP_VSYNC_END */ |
8af6ff01 | 3674 | r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */ |
478d7df8 | 3675 | r = FLD_MOD(r, sync_end, 18, 18); /* VP_HSYNC_END */ |
8af6ff01 AT |
3676 | dsi_write_reg(dsidev, DSI_CTRL, r); |
3677 | } | |
3678 | ||
9e7e9372 | 3679 | static void dsi_config_blanking_modes(struct platform_device *dsidev) |
8af6ff01 | 3680 | { |
0b3ffe39 AT |
3681 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3682 | int blanking_mode = dsi->vm_timings.blanking_mode; | |
3683 | int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode; | |
3684 | int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode; | |
3685 | int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode; | |
8af6ff01 AT |
3686 | u32 r; |
3687 | ||
3688 | /* | |
3689 | * 0 = TX FIFO packets sent or LPS in corresponding blanking periods | |
3690 | * 1 = Long blanking packets are sent in corresponding blanking periods | |
3691 | */ | |
3692 | r = dsi_read_reg(dsidev, DSI_CTRL); | |
3693 | r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */ | |
3694 | r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */ | |
3695 | r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */ | |
3696 | r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */ | |
3697 | dsi_write_reg(dsidev, DSI_CTRL, r); | |
3698 | } | |
3699 | ||
6f28c296 AT |
3700 | /* |
3701 | * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3 | |
3702 | * results in maximum transition time for data and clock lanes to enter and | |
3703 | * exit HS mode. Hence, this is the scenario where the least amount of command | |
3704 | * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS | |
3705 | * clock cycles that can be used to interleave command mode data in HS so that | |
3706 | * all scenarios are satisfied. | |
3707 | */ | |
3708 | static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs, | |
3709 | int exit_hs, int exiths_clk, int ddr_pre, int ddr_post) | |
3710 | { | |
3711 | int transition; | |
3712 | ||
3713 | /* | |
3714 | * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition | |
3715 | * time of data lanes only, if it isn't set, we need to consider HS | |
3716 | * transition time of both data and clock lanes. HS transition time | |
3717 | * of Scenario 3 is considered. | |
3718 | */ | |
3719 | if (ddr_alwon) { | |
3720 | transition = enter_hs + exit_hs + max(enter_hs, 2) + 1; | |
3721 | } else { | |
3722 | int trans1, trans2; | |
3723 | trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1; | |
3724 | trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre + | |
3725 | enter_hs + 1; | |
3726 | transition = max(trans1, trans2); | |
3727 | } | |
3728 | ||
3729 | return blank > transition ? blank - transition : 0; | |
3730 | } | |
3731 | ||
3732 | /* | |
3733 | * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1 | |
3734 | * results in maximum transition time for data lanes to enter and exit LP mode. | |
3735 | * Hence, this is the scenario where the least amount of command mode data can | |
3736 | * be interleaved. We program the minimum amount of bytes that can be | |
3737 | * interleaved in LP so that all scenarios are satisfied. | |
3738 | */ | |
3739 | static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs, | |
3740 | int lp_clk_div, int tdsi_fclk) | |
3741 | { | |
3742 | int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */ | |
3743 | int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */ | |
3744 | int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */ | |
3745 | int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */ | |
3746 | int lp_inter; /* cmd mode data that can be interleaved, in bytes */ | |
3747 | ||
3748 | /* maximum LP transition time according to Scenario 1 */ | |
3749 | trans_lp = exit_hs + max(enter_hs, 2) + 1; | |
3750 | ||
3751 | /* CLKIN4DDR = 16 * TXBYTECLKHS */ | |
3752 | tlp_avail = thsbyte_clk * (blank - trans_lp); | |
3753 | ||
2e063c30 | 3754 | ttxclkesc = tdsi_fclk * lp_clk_div; |
6f28c296 AT |
3755 | |
3756 | lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc - | |
3757 | 26) / 16; | |
3758 | ||
3759 | return max(lp_inter, 0); | |
3760 | } | |
3761 | ||
5761217a | 3762 | static void dsi_config_cmd_mode_interleaving(struct platform_device *dsidev) |
6f28c296 | 3763 | { |
6f28c296 AT |
3764 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3765 | int blanking_mode; | |
3766 | int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode; | |
3767 | int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div; | |
3768 | int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat; | |
3769 | int tclk_trail, ths_exit, exiths_clk; | |
3770 | bool ddr_alwon; | |
e67458a8 | 3771 | struct omap_video_timings *timings = &dsi->timings; |
02c3960b | 3772 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
6f28c296 | 3773 | int ndl = dsi->num_lanes_used - 1; |
a0d269ec | 3774 | int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.regm_dsi + 1; |
6f28c296 AT |
3775 | int hsa_interleave_hs = 0, hsa_interleave_lp = 0; |
3776 | int hfp_interleave_hs = 0, hfp_interleave_lp = 0; | |
3777 | int hbp_interleave_hs = 0, hbp_interleave_lp = 0; | |
3778 | int bl_interleave_hs = 0, bl_interleave_lp = 0; | |
3779 | u32 r; | |
3780 | ||
3781 | r = dsi_read_reg(dsidev, DSI_CTRL); | |
3782 | blanking_mode = FLD_GET(r, 20, 20); | |
3783 | hfp_blanking_mode = FLD_GET(r, 21, 21); | |
3784 | hbp_blanking_mode = FLD_GET(r, 22, 22); | |
3785 | hsa_blanking_mode = FLD_GET(r, 23, 23); | |
3786 | ||
3787 | r = dsi_read_reg(dsidev, DSI_VM_TIMING1); | |
3788 | hbp = FLD_GET(r, 11, 0); | |
3789 | hfp = FLD_GET(r, 23, 12); | |
3790 | hsa = FLD_GET(r, 31, 24); | |
3791 | ||
3792 | r = dsi_read_reg(dsidev, DSI_CLK_TIMING); | |
3793 | ddr_clk_post = FLD_GET(r, 7, 0); | |
3794 | ddr_clk_pre = FLD_GET(r, 15, 8); | |
3795 | ||
3796 | r = dsi_read_reg(dsidev, DSI_VM_TIMING7); | |
3797 | exit_hs_mode_lat = FLD_GET(r, 15, 0); | |
3798 | enter_hs_mode_lat = FLD_GET(r, 31, 16); | |
3799 | ||
3800 | r = dsi_read_reg(dsidev, DSI_CLK_CTRL); | |
3801 | lp_clk_div = FLD_GET(r, 12, 0); | |
3802 | ddr_alwon = FLD_GET(r, 13, 13); | |
3803 | ||
3804 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); | |
3805 | ths_exit = FLD_GET(r, 7, 0); | |
3806 | ||
3807 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); | |
3808 | tclk_trail = FLD_GET(r, 15, 8); | |
3809 | ||
3810 | exiths_clk = ths_exit + tclk_trail; | |
3811 | ||
3812 | width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); | |
3813 | bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl); | |
3814 | ||
3815 | if (!hsa_blanking_mode) { | |
3816 | hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon, | |
3817 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3818 | exiths_clk, ddr_clk_pre, ddr_clk_post); | |
3819 | hsa_interleave_lp = dsi_compute_interleave_lp(hsa, | |
3820 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3821 | lp_clk_div, dsi_fclk_hsdiv); | |
3822 | } | |
3823 | ||
3824 | if (!hfp_blanking_mode) { | |
3825 | hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon, | |
3826 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3827 | exiths_clk, ddr_clk_pre, ddr_clk_post); | |
3828 | hfp_interleave_lp = dsi_compute_interleave_lp(hfp, | |
3829 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3830 | lp_clk_div, dsi_fclk_hsdiv); | |
3831 | } | |
3832 | ||
3833 | if (!hbp_blanking_mode) { | |
3834 | hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon, | |
3835 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3836 | exiths_clk, ddr_clk_pre, ddr_clk_post); | |
3837 | ||
3838 | hbp_interleave_lp = dsi_compute_interleave_lp(hbp, | |
3839 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3840 | lp_clk_div, dsi_fclk_hsdiv); | |
3841 | } | |
3842 | ||
3843 | if (!blanking_mode) { | |
3844 | bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon, | |
3845 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3846 | exiths_clk, ddr_clk_pre, ddr_clk_post); | |
3847 | ||
3848 | bl_interleave_lp = dsi_compute_interleave_lp(bllp, | |
3849 | enter_hs_mode_lat, exit_hs_mode_lat, | |
3850 | lp_clk_div, dsi_fclk_hsdiv); | |
3851 | } | |
3852 | ||
3853 | DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n", | |
3854 | hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs, | |
3855 | bl_interleave_hs); | |
3856 | ||
3857 | DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n", | |
3858 | hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp, | |
3859 | bl_interleave_lp); | |
3860 | ||
3861 | r = dsi_read_reg(dsidev, DSI_VM_TIMING4); | |
3862 | r = FLD_MOD(r, hsa_interleave_hs, 23, 16); | |
3863 | r = FLD_MOD(r, hfp_interleave_hs, 15, 8); | |
3864 | r = FLD_MOD(r, hbp_interleave_hs, 7, 0); | |
3865 | dsi_write_reg(dsidev, DSI_VM_TIMING4, r); | |
3866 | ||
3867 | r = dsi_read_reg(dsidev, DSI_VM_TIMING5); | |
3868 | r = FLD_MOD(r, hsa_interleave_lp, 23, 16); | |
3869 | r = FLD_MOD(r, hfp_interleave_lp, 15, 8); | |
3870 | r = FLD_MOD(r, hbp_interleave_lp, 7, 0); | |
3871 | dsi_write_reg(dsidev, DSI_VM_TIMING5, r); | |
3872 | ||
3873 | r = dsi_read_reg(dsidev, DSI_VM_TIMING6); | |
3874 | r = FLD_MOD(r, bl_interleave_hs, 31, 15); | |
3875 | r = FLD_MOD(r, bl_interleave_lp, 16, 0); | |
3876 | dsi_write_reg(dsidev, DSI_VM_TIMING6, r); | |
3877 | } | |
3878 | ||
5761217a | 3879 | static int dsi_proto_config(struct platform_device *dsidev) |
3de7a1dc | 3880 | { |
02c3960b | 3881 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
3882 | u32 r; |
3883 | int buswidth = 0; | |
3884 | ||
a72b64b9 | 3885 | dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32, |
dd8079d6 TV |
3886 | DSI_FIFO_SIZE_32, |
3887 | DSI_FIFO_SIZE_32, | |
3888 | DSI_FIFO_SIZE_32); | |
3de7a1dc | 3889 | |
a72b64b9 | 3890 | dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32, |
dd8079d6 TV |
3891 | DSI_FIFO_SIZE_32, |
3892 | DSI_FIFO_SIZE_32, | |
3893 | DSI_FIFO_SIZE_32); | |
3de7a1dc TV |
3894 | |
3895 | /* XXX what values for the timeouts? */ | |
a72b64b9 AT |
3896 | dsi_set_stop_state_counter(dsidev, 0x1000, false, false); |
3897 | dsi_set_ta_timeout(dsidev, 0x1fff, true, true); | |
3898 | dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true); | |
3899 | dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true); | |
3de7a1dc | 3900 | |
02c3960b | 3901 | switch (dsi_get_pixel_size(dsi->pix_fmt)) { |
3de7a1dc TV |
3902 | case 16: |
3903 | buswidth = 0; | |
3904 | break; | |
3905 | case 18: | |
3906 | buswidth = 1; | |
3907 | break; | |
3908 | case 24: | |
3909 | buswidth = 2; | |
3910 | break; | |
3911 | default: | |
3912 | BUG(); | |
c6eee968 | 3913 | return -EINVAL; |
3de7a1dc TV |
3914 | } |
3915 | ||
a72b64b9 | 3916 | r = dsi_read_reg(dsidev, DSI_CTRL); |
3de7a1dc TV |
3917 | r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */ |
3918 | r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */ | |
3919 | r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */ | |
3920 | r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/ | |
3921 | r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */ | |
3922 | r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */ | |
3de7a1dc TV |
3923 | r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */ |
3924 | r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */ | |
9613c02b AT |
3925 | if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { |
3926 | r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */ | |
3927 | /* DCS_CMD_CODE, 1=start, 0=continue */ | |
3928 | r = FLD_MOD(r, 0, 25, 25); | |
3929 | } | |
3de7a1dc | 3930 | |
a72b64b9 | 3931 | dsi_write_reg(dsidev, DSI_CTRL, r); |
3de7a1dc | 3932 | |
9e7e9372 | 3933 | dsi_config_vp_num_line_buffers(dsidev); |
8af6ff01 | 3934 | |
dca2b152 | 3935 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
9e7e9372 AT |
3936 | dsi_config_vp_sync_events(dsidev); |
3937 | dsi_config_blanking_modes(dsidev); | |
5761217a | 3938 | dsi_config_cmd_mode_interleaving(dsidev); |
8af6ff01 AT |
3939 | } |
3940 | ||
a72b64b9 AT |
3941 | dsi_vc_initial_config(dsidev, 0); |
3942 | dsi_vc_initial_config(dsidev, 1); | |
3943 | dsi_vc_initial_config(dsidev, 2); | |
3944 | dsi_vc_initial_config(dsidev, 3); | |
3de7a1dc TV |
3945 | |
3946 | return 0; | |
3947 | } | |
3948 | ||
9e7e9372 | 3949 | static void dsi_proto_timings(struct platform_device *dsidev) |
3de7a1dc | 3950 | { |
db18644f | 3951 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
3952 | unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail; |
3953 | unsigned tclk_pre, tclk_post; | |
3954 | unsigned ths_prepare, ths_prepare_ths_zero, ths_zero; | |
3955 | unsigned ths_trail, ths_exit; | |
3956 | unsigned ddr_clk_pre, ddr_clk_post; | |
3957 | unsigned enter_hs_mode_lat, exit_hs_mode_lat; | |
3958 | unsigned ths_eot; | |
db18644f | 3959 | int ndl = dsi->num_lanes_used - 1; |
3de7a1dc TV |
3960 | u32 r; |
3961 | ||
a72b64b9 | 3962 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
3de7a1dc TV |
3963 | ths_prepare = FLD_GET(r, 31, 24); |
3964 | ths_prepare_ths_zero = FLD_GET(r, 23, 16); | |
3965 | ths_zero = ths_prepare_ths_zero - ths_prepare; | |
3966 | ths_trail = FLD_GET(r, 15, 8); | |
3967 | ths_exit = FLD_GET(r, 7, 0); | |
3968 | ||
a72b64b9 | 3969 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
e84dc1cc | 3970 | tlpx = FLD_GET(r, 20, 16) * 2; |
3de7a1dc TV |
3971 | tclk_trail = FLD_GET(r, 15, 8); |
3972 | tclk_zero = FLD_GET(r, 7, 0); | |
3973 | ||
a72b64b9 | 3974 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
3de7a1dc TV |
3975 | tclk_prepare = FLD_GET(r, 7, 0); |
3976 | ||
3977 | /* min 8*UI */ | |
3978 | tclk_pre = 20; | |
3979 | /* min 60ns + 52*UI */ | |
a72b64b9 | 3980 | tclk_post = ns2ddr(dsidev, 60) + 26; |
3de7a1dc | 3981 | |
8af6ff01 | 3982 | ths_eot = DIV_ROUND_UP(4, ndl); |
3de7a1dc TV |
3983 | |
3984 | ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare, | |
3985 | 4); | |
3986 | ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot; | |
3987 | ||
3988 | BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255); | |
3989 | BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255); | |
3990 | ||
a72b64b9 | 3991 | r = dsi_read_reg(dsidev, DSI_CLK_TIMING); |
3de7a1dc TV |
3992 | r = FLD_MOD(r, ddr_clk_pre, 15, 8); |
3993 | r = FLD_MOD(r, ddr_clk_post, 7, 0); | |
a72b64b9 | 3994 | dsi_write_reg(dsidev, DSI_CLK_TIMING, r); |
3de7a1dc TV |
3995 | |
3996 | DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n", | |
3997 | ddr_clk_pre, | |
3998 | ddr_clk_post); | |
3999 | ||
4000 | enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) + | |
4001 | DIV_ROUND_UP(ths_prepare, 4) + | |
4002 | DIV_ROUND_UP(ths_zero + 3, 4); | |
4003 | ||
4004 | exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot; | |
4005 | ||
4006 | r = FLD_VAL(enter_hs_mode_lat, 31, 16) | | |
4007 | FLD_VAL(exit_hs_mode_lat, 15, 0); | |
a72b64b9 | 4008 | dsi_write_reg(dsidev, DSI_VM_TIMING7, r); |
3de7a1dc TV |
4009 | |
4010 | DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n", | |
4011 | enter_hs_mode_lat, exit_hs_mode_lat); | |
8af6ff01 | 4012 | |
dca2b152 | 4013 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
8af6ff01 | 4014 | /* TODO: Implement a video mode check_timings function */ |
0b3ffe39 AT |
4015 | int hsa = dsi->vm_timings.hsa; |
4016 | int hfp = dsi->vm_timings.hfp; | |
4017 | int hbp = dsi->vm_timings.hbp; | |
4018 | int vsa = dsi->vm_timings.vsa; | |
4019 | int vfp = dsi->vm_timings.vfp; | |
4020 | int vbp = dsi->vm_timings.vbp; | |
4021 | int window_sync = dsi->vm_timings.window_sync; | |
478d7df8 | 4022 | bool hsync_end; |
e67458a8 | 4023 | struct omap_video_timings *timings = &dsi->timings; |
02c3960b | 4024 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
8af6ff01 AT |
4025 | int tl, t_he, width_bytes; |
4026 | ||
478d7df8 | 4027 | hsync_end = dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE; |
8af6ff01 AT |
4028 | t_he = hsync_end ? |
4029 | ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0; | |
4030 | ||
4031 | width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); | |
4032 | ||
4033 | /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */ | |
4034 | tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp + | |
4035 | DIV_ROUND_UP(width_bytes + 6, ndl) + hbp; | |
4036 | ||
4037 | DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp, | |
4038 | hfp, hsync_end ? hsa : 0, tl); | |
4039 | DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp, | |
4040 | vsa, timings->y_res); | |
4041 | ||
4042 | r = dsi_read_reg(dsidev, DSI_VM_TIMING1); | |
4043 | r = FLD_MOD(r, hbp, 11, 0); /* HBP */ | |
4044 | r = FLD_MOD(r, hfp, 23, 12); /* HFP */ | |
4045 | r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */ | |
4046 | dsi_write_reg(dsidev, DSI_VM_TIMING1, r); | |
4047 | ||
4048 | r = dsi_read_reg(dsidev, DSI_VM_TIMING2); | |
4049 | r = FLD_MOD(r, vbp, 7, 0); /* VBP */ | |
4050 | r = FLD_MOD(r, vfp, 15, 8); /* VFP */ | |
4051 | r = FLD_MOD(r, vsa, 23, 16); /* VSA */ | |
4052 | r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */ | |
4053 | dsi_write_reg(dsidev, DSI_VM_TIMING2, r); | |
4054 | ||
4055 | r = dsi_read_reg(dsidev, DSI_VM_TIMING3); | |
4056 | r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */ | |
4057 | r = FLD_MOD(r, tl, 31, 16); /* TL */ | |
4058 | dsi_write_reg(dsidev, DSI_VM_TIMING3, r); | |
4059 | } | |
4060 | } | |
4061 | ||
e4a9e94c TV |
4062 | int omapdss_dsi_configure_pins(struct omap_dss_device *dssdev, |
4063 | const struct omap_dsi_pin_config *pin_cfg) | |
4064 | { | |
4065 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); | |
4066 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
4067 | int num_pins; | |
4068 | const int *pins; | |
4069 | struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; | |
4070 | int num_lanes; | |
4071 | int i; | |
4072 | ||
4073 | static const enum dsi_lane_function functions[] = { | |
4074 | DSI_LANE_CLK, | |
4075 | DSI_LANE_DATA1, | |
4076 | DSI_LANE_DATA2, | |
4077 | DSI_LANE_DATA3, | |
4078 | DSI_LANE_DATA4, | |
4079 | }; | |
4080 | ||
4081 | num_pins = pin_cfg->num_pins; | |
4082 | pins = pin_cfg->pins; | |
4083 | ||
4084 | if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2 | |
4085 | || num_pins % 2 != 0) | |
4086 | return -EINVAL; | |
4087 | ||
4088 | for (i = 0; i < DSI_MAX_NR_LANES; ++i) | |
4089 | lanes[i].function = DSI_LANE_UNUSED; | |
4090 | ||
4091 | num_lanes = 0; | |
4092 | ||
4093 | for (i = 0; i < num_pins; i += 2) { | |
4094 | u8 lane, pol; | |
4095 | int dx, dy; | |
4096 | ||
4097 | dx = pins[i]; | |
4098 | dy = pins[i + 1]; | |
4099 | ||
4100 | if (dx < 0 || dx >= dsi->num_lanes_supported * 2) | |
4101 | return -EINVAL; | |
4102 | ||
4103 | if (dy < 0 || dy >= dsi->num_lanes_supported * 2) | |
4104 | return -EINVAL; | |
4105 | ||
4106 | if (dx & 1) { | |
4107 | if (dy != dx - 1) | |
4108 | return -EINVAL; | |
4109 | pol = 1; | |
4110 | } else { | |
4111 | if (dy != dx + 1) | |
4112 | return -EINVAL; | |
4113 | pol = 0; | |
4114 | } | |
4115 | ||
4116 | lane = dx / 2; | |
4117 | ||
4118 | lanes[lane].function = functions[i / 2]; | |
4119 | lanes[lane].polarity = pol; | |
4120 | num_lanes++; | |
4121 | } | |
4122 | ||
4123 | memcpy(dsi->lanes, lanes, sizeof(dsi->lanes)); | |
4124 | dsi->num_lanes_used = num_lanes; | |
4125 | ||
4126 | return 0; | |
4127 | } | |
4128 | EXPORT_SYMBOL(omapdss_dsi_configure_pins); | |
4129 | ||
9a147a65 | 4130 | int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel) |
8af6ff01 AT |
4131 | { |
4132 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); | |
e67458a8 | 4133 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
5761217a | 4134 | struct omap_overlay_manager *mgr = dsi->output.manager; |
02c3960b | 4135 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
1f68d9c4 | 4136 | struct omap_dss_device *out = &dsi->output; |
8af6ff01 AT |
4137 | u8 data_type; |
4138 | u16 word_count; | |
33ca237f | 4139 | int r; |
8af6ff01 | 4140 | |
b7dec9b6 TV |
4141 | if (out == NULL || out->manager == NULL) { |
4142 | DSSERR("failed to enable display: no output/manager\n"); | |
4143 | return -ENODEV; | |
4144 | } | |
4145 | ||
4146 | r = dsi_display_init_dispc(dsidev, mgr); | |
4147 | if (r) | |
4148 | goto err_init_dispc; | |
4149 | ||
dca2b152 | 4150 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
02c3960b | 4151 | switch (dsi->pix_fmt) { |
9a147a65 TV |
4152 | case OMAP_DSS_DSI_FMT_RGB888: |
4153 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24; | |
4154 | break; | |
4155 | case OMAP_DSS_DSI_FMT_RGB666: | |
4156 | data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18; | |
4157 | break; | |
4158 | case OMAP_DSS_DSI_FMT_RGB666_PACKED: | |
4159 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18; | |
4160 | break; | |
4161 | case OMAP_DSS_DSI_FMT_RGB565: | |
4162 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16; | |
4163 | break; | |
4164 | default: | |
b7dec9b6 TV |
4165 | r = -EINVAL; |
4166 | goto err_pix_fmt; | |
9a147a65 | 4167 | }; |
8af6ff01 | 4168 | |
9a147a65 TV |
4169 | dsi_if_enable(dsidev, false); |
4170 | dsi_vc_enable(dsidev, channel, false); | |
8af6ff01 | 4171 | |
9a147a65 TV |
4172 | /* MODE, 1 = video mode */ |
4173 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4); | |
8af6ff01 | 4174 | |
e67458a8 | 4175 | word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8); |
8af6ff01 | 4176 | |
9a147a65 TV |
4177 | dsi_vc_write_long_header(dsidev, channel, data_type, |
4178 | word_count, 0); | |
8af6ff01 | 4179 | |
9a147a65 TV |
4180 | dsi_vc_enable(dsidev, channel, true); |
4181 | dsi_if_enable(dsidev, true); | |
4182 | } | |
8af6ff01 | 4183 | |
eea8340a | 4184 | r = dss_mgr_enable(mgr); |
b7dec9b6 TV |
4185 | if (r) |
4186 | goto err_mgr_enable; | |
8af6ff01 AT |
4187 | |
4188 | return 0; | |
b7dec9b6 TV |
4189 | |
4190 | err_mgr_enable: | |
4191 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { | |
4192 | dsi_if_enable(dsidev, false); | |
4193 | dsi_vc_enable(dsidev, channel, false); | |
4194 | } | |
4195 | err_pix_fmt: | |
4196 | dsi_display_uninit_dispc(dsidev, mgr); | |
4197 | err_init_dispc: | |
4198 | return r; | |
8af6ff01 | 4199 | } |
9a147a65 | 4200 | EXPORT_SYMBOL(dsi_enable_video_output); |
8af6ff01 | 4201 | |
9a147a65 | 4202 | void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel) |
8af6ff01 AT |
4203 | { |
4204 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); | |
dca2b152 | 4205 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
5761217a | 4206 | struct omap_overlay_manager *mgr = dsi->output.manager; |
8af6ff01 | 4207 | |
dca2b152 | 4208 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
9a147a65 TV |
4209 | dsi_if_enable(dsidev, false); |
4210 | dsi_vc_enable(dsidev, channel, false); | |
8af6ff01 | 4211 | |
9a147a65 TV |
4212 | /* MODE, 0 = command mode */ |
4213 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4); | |
8af6ff01 | 4214 | |
9a147a65 TV |
4215 | dsi_vc_enable(dsidev, channel, true); |
4216 | dsi_if_enable(dsidev, true); | |
4217 | } | |
8af6ff01 | 4218 | |
eea8340a | 4219 | dss_mgr_disable(mgr); |
b7dec9b6 TV |
4220 | |
4221 | dsi_display_uninit_dispc(dsidev, mgr); | |
3de7a1dc | 4222 | } |
9a147a65 | 4223 | EXPORT_SYMBOL(dsi_disable_video_output); |
3de7a1dc | 4224 | |
5761217a | 4225 | static void dsi_update_screen_dispc(struct platform_device *dsidev) |
3de7a1dc | 4226 | { |
f1da39d9 | 4227 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
5761217a | 4228 | struct omap_overlay_manager *mgr = dsi->output.manager; |
3de7a1dc TV |
4229 | unsigned bytespp; |
4230 | unsigned bytespl; | |
4231 | unsigned bytespf; | |
4232 | unsigned total_len; | |
4233 | unsigned packet_payload; | |
4234 | unsigned packet_len; | |
4235 | u32 l; | |
0f16aa0a | 4236 | int r; |
f1da39d9 | 4237 | const unsigned channel = dsi->update_channel; |
99322577 | 4238 | const unsigned line_buf_size = dsi->line_buffer_size; |
55cd63ac AT |
4239 | u16 w = dsi->timings.x_res; |
4240 | u16 h = dsi->timings.y_res; | |
3de7a1dc | 4241 | |
5476e74a | 4242 | DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h); |
3de7a1dc | 4243 | |
d6049144 | 4244 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP); |
18946f62 | 4245 | |
02c3960b | 4246 | bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8; |
3de7a1dc TV |
4247 | bytespl = w * bytespp; |
4248 | bytespf = bytespl * h; | |
4249 | ||
4250 | /* NOTE: packet_payload has to be equal to N * bytespl, where N is | |
4251 | * number of lines in a packet. See errata about VP_CLK_RATIO */ | |
4252 | ||
4253 | if (bytespf < line_buf_size) | |
4254 | packet_payload = bytespf; | |
4255 | else | |
4256 | packet_payload = (line_buf_size) / bytespl * bytespl; | |
4257 | ||
4258 | packet_len = packet_payload + 1; /* 1 byte for DCS cmd */ | |
4259 | total_len = (bytespf / packet_payload) * packet_len; | |
4260 | ||
4261 | if (bytespf % packet_payload) | |
4262 | total_len += (bytespf % packet_payload) + 1; | |
4263 | ||
3de7a1dc | 4264 | l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */ |
a72b64b9 | 4265 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
3de7a1dc | 4266 | |
7a7c48f9 | 4267 | dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE, |
a72b64b9 | 4268 | packet_len, 0); |
3de7a1dc | 4269 | |
f1da39d9 | 4270 | if (dsi->te_enabled) |
3de7a1dc TV |
4271 | l = FLD_MOD(l, 1, 30, 30); /* TE_EN */ |
4272 | else | |
4273 | l = FLD_MOD(l, 1, 31, 31); /* TE_START */ | |
a72b64b9 | 4274 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
3de7a1dc TV |
4275 | |
4276 | /* We put SIDLEMODE to no-idle for the duration of the transfer, | |
4277 | * because DSS interrupts are not capable of waking up the CPU and the | |
4278 | * framedone interrupt could be delayed for quite a long time. I think | |
4279 | * the same goes for any DSS interrupts, but for some reason I have not | |
4280 | * seen the problem anywhere else than here. | |
4281 | */ | |
4282 | dispc_disable_sidle(); | |
4283 | ||
a72b64b9 | 4284 | dsi_perf_mark_start(dsidev); |
18946f62 | 4285 | |
49dbf589 AT |
4286 | r = schedule_delayed_work(&dsi->framedone_timeout_work, |
4287 | msecs_to_jiffies(250)); | |
0f16aa0a | 4288 | BUG_ON(r == 0); |
18946f62 | 4289 | |
eea8340a | 4290 | dss_mgr_set_timings(mgr, &dsi->timings); |
55cd63ac | 4291 | |
eea8340a | 4292 | dss_mgr_start_update(mgr); |
3de7a1dc | 4293 | |
f1da39d9 | 4294 | if (dsi->te_enabled) { |
3de7a1dc TV |
4295 | /* disable LP_RX_TO, so that we can receive TE. Time to wait |
4296 | * for TE is longer than the timer allows */ | |
a72b64b9 | 4297 | REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */ |
3de7a1dc | 4298 | |
a72b64b9 | 4299 | dsi_vc_send_bta(dsidev, channel); |
3de7a1dc TV |
4300 | |
4301 | #ifdef DSI_CATCH_MISSING_TE | |
f1da39d9 | 4302 | mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250)); |
3de7a1dc TV |
4303 | #endif |
4304 | } | |
4305 | } | |
4306 | ||
4307 | #ifdef DSI_CATCH_MISSING_TE | |
4308 | static void dsi_te_timeout(unsigned long arg) | |
4309 | { | |
4310 | DSSERR("TE not received for 250ms!\n"); | |
4311 | } | |
4312 | #endif | |
4313 | ||
a72b64b9 | 4314 | static void dsi_handle_framedone(struct platform_device *dsidev, int error) |
3de7a1dc | 4315 | { |
f1da39d9 AT |
4316 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4317 | ||
3de7a1dc TV |
4318 | /* SIDLEMODE back to smart-idle */ |
4319 | dispc_enable_sidle(); | |
4320 | ||
f1da39d9 | 4321 | if (dsi->te_enabled) { |
18946f62 | 4322 | /* enable LP_RX_TO again after the TE */ |
a72b64b9 | 4323 | REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */ |
3de7a1dc TV |
4324 | } |
4325 | ||
f1da39d9 | 4326 | dsi->framedone_callback(error, dsi->framedone_data); |
ab83b14c TV |
4327 | |
4328 | if (!error) | |
a72b64b9 | 4329 | dsi_perf_show(dsidev, "DISPC"); |
18946f62 | 4330 | } |
3de7a1dc | 4331 | |
ab83b14c | 4332 | static void dsi_framedone_timeout_work_callback(struct work_struct *work) |
18946f62 | 4333 | { |
f1da39d9 AT |
4334 | struct dsi_data *dsi = container_of(work, struct dsi_data, |
4335 | framedone_timeout_work.work); | |
ab83b14c TV |
4336 | /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after |
4337 | * 250ms which would conflict with this timeout work. What should be | |
4338 | * done is first cancel the transfer on the HW, and then cancel the | |
4339 | * possibly scheduled framedone work. However, cancelling the transfer | |
4340 | * on the HW is buggy, and would probably require resetting the whole | |
4341 | * DSI */ | |
18946f62 | 4342 | |
ab83b14c | 4343 | DSSERR("Framedone not received for 250ms!\n"); |
3de7a1dc | 4344 | |
f1da39d9 | 4345 | dsi_handle_framedone(dsi->pdev, -ETIMEDOUT); |
3de7a1dc TV |
4346 | } |
4347 | ||
1550202d | 4348 | static void dsi_framedone_irq_callback(void *data) |
3de7a1dc | 4349 | { |
9e7e9372 | 4350 | struct platform_device *dsidev = (struct platform_device *) data; |
f1da39d9 AT |
4351 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4352 | ||
ab83b14c TV |
4353 | /* Note: We get FRAMEDONE when DISPC has finished sending pixels and |
4354 | * turns itself off. However, DSI still has the pixels in its buffers, | |
4355 | * and is sending the data. | |
4356 | */ | |
3de7a1dc | 4357 | |
136b5721 | 4358 | cancel_delayed_work(&dsi->framedone_timeout_work); |
3de7a1dc | 4359 | |
a72b64b9 | 4360 | dsi_handle_framedone(dsidev, 0); |
18946f62 | 4361 | } |
3de7a1dc | 4362 | |
5476e74a TV |
4363 | int omap_dsi_update(struct omap_dss_device *dssdev, int channel, |
4364 | void (*callback)(int, void *), void *data) | |
18946f62 | 4365 | { |
a72b64b9 | 4366 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
5476e74a | 4367 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
18946f62 | 4368 | u16 dw, dh; |
3de7a1dc | 4369 | |
a72b64b9 | 4370 | dsi_perf_mark_setup(dsidev); |
3de7a1dc | 4371 | |
f1da39d9 | 4372 | dsi->update_channel = channel; |
3de7a1dc | 4373 | |
4a9e78ab TV |
4374 | dsi->framedone_callback = callback; |
4375 | dsi->framedone_data = data; | |
e9c31afc | 4376 | |
e352574d AT |
4377 | dw = dsi->timings.x_res; |
4378 | dh = dsi->timings.y_res; | |
e9c31afc | 4379 | |
5476e74a TV |
4380 | #ifdef DEBUG |
4381 | dsi->update_bytes = dw * dh * | |
02c3960b | 4382 | dsi_get_pixel_size(dsi->pix_fmt) / 8; |
5476e74a | 4383 | #endif |
5761217a | 4384 | dsi_update_screen_dispc(dsidev); |
3de7a1dc | 4385 | |
3de7a1dc TV |
4386 | return 0; |
4387 | } | |
18946f62 | 4388 | EXPORT_SYMBOL(omap_dsi_update); |
3de7a1dc TV |
4389 | |
4390 | /* Display funcs */ | |
4391 | ||
5761217a | 4392 | static int dsi_configure_dispc_clocks(struct platform_device *dsidev) |
3de7a1dc | 4393 | { |
7d2572f8 AT |
4394 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4395 | struct dispc_clock_info dispc_cinfo; | |
3de7a1dc | 4396 | int r; |
17518189 | 4397 | unsigned long fck; |
7d2572f8 AT |
4398 | |
4399 | fck = dsi_get_pll_hsdiv_dispc_rate(dsidev); | |
4400 | ||
a0d269ec TV |
4401 | dispc_cinfo.lck_div = dsi->user_dispc_cinfo.lck_div; |
4402 | dispc_cinfo.pck_div = dsi->user_dispc_cinfo.pck_div; | |
7d2572f8 AT |
4403 | |
4404 | r = dispc_calc_clock_rates(fck, &dispc_cinfo); | |
4405 | if (r) { | |
4406 | DSSERR("Failed to calc dispc clocks\n"); | |
4407 | return r; | |
4408 | } | |
4409 | ||
4410 | dsi->mgr_config.clock_info = dispc_cinfo; | |
4411 | ||
4412 | return 0; | |
4413 | } | |
4414 | ||
b7dec9b6 TV |
4415 | static int dsi_display_init_dispc(struct platform_device *dsidev, |
4416 | struct omap_overlay_manager *mgr) | |
7d2572f8 | 4417 | { |
7d2572f8 | 4418 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
7d2572f8 | 4419 | int r; |
3de7a1dc | 4420 | |
4ce9e33c TV |
4421 | dss_select_lcd_clk_source(mgr->id, dsi->module_id == 0 ? |
4422 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : | |
4423 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC); | |
5476e74a | 4424 | |
dca2b152 | 4425 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) { |
1550202d TV |
4426 | r = dss_mgr_register_framedone_handler(mgr, |
4427 | dsi_framedone_irq_callback, dsidev); | |
8af6ff01 | 4428 | if (r) { |
1550202d | 4429 | DSSERR("can't register FRAMEDONE handler\n"); |
7d2572f8 | 4430 | goto err; |
8af6ff01 AT |
4431 | } |
4432 | ||
7d2572f8 AT |
4433 | dsi->mgr_config.stallmode = true; |
4434 | dsi->mgr_config.fifohandcheck = true; | |
8af6ff01 | 4435 | } else { |
7d2572f8 AT |
4436 | dsi->mgr_config.stallmode = false; |
4437 | dsi->mgr_config.fifohandcheck = false; | |
3de7a1dc TV |
4438 | } |
4439 | ||
bd5a7b11 AT |
4440 | /* |
4441 | * override interlace, logic level and edge related parameters in | |
4442 | * omap_video_timings with default values | |
4443 | */ | |
e67458a8 AT |
4444 | dsi->timings.interlace = false; |
4445 | dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH; | |
4446 | dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH; | |
4447 | dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE; | |
4448 | dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH; | |
4449 | dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES; | |
bd5a7b11 | 4450 | |
eea8340a | 4451 | dss_mgr_set_timings(mgr, &dsi->timings); |
bd5a7b11 | 4452 | |
5761217a | 4453 | r = dsi_configure_dispc_clocks(dsidev); |
7d2572f8 AT |
4454 | if (r) |
4455 | goto err1; | |
4456 | ||
4457 | dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS; | |
4458 | dsi->mgr_config.video_port_width = | |
02c3960b | 4459 | dsi_get_pixel_size(dsi->pix_fmt); |
7d2572f8 AT |
4460 | dsi->mgr_config.lcden_sig_polarity = 0; |
4461 | ||
eea8340a | 4462 | dss_mgr_set_lcd_config(mgr, &dsi->mgr_config); |
d21f43bc | 4463 | |
3de7a1dc | 4464 | return 0; |
7d2572f8 | 4465 | err1: |
dca2b152 | 4466 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) |
1550202d TV |
4467 | dss_mgr_unregister_framedone_handler(mgr, |
4468 | dsi_framedone_irq_callback, dsidev); | |
7d2572f8 | 4469 | err: |
b7dec9b6 | 4470 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); |
7d2572f8 | 4471 | return r; |
3de7a1dc TV |
4472 | } |
4473 | ||
b7dec9b6 TV |
4474 | static void dsi_display_uninit_dispc(struct platform_device *dsidev, |
4475 | struct omap_overlay_manager *mgr) | |
3de7a1dc | 4476 | { |
dca2b152 AT |
4477 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
4478 | ||
1550202d TV |
4479 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) |
4480 | dss_mgr_unregister_framedone_handler(mgr, | |
4481 | dsi_framedone_irq_callback, dsidev); | |
b7dec9b6 TV |
4482 | |
4483 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); | |
3de7a1dc TV |
4484 | } |
4485 | ||
5761217a | 4486 | static int dsi_configure_dsi_clocks(struct platform_device *dsidev) |
3de7a1dc | 4487 | { |
a0d269ec | 4488 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
4489 | struct dsi_clock_info cinfo; |
4490 | int r; | |
4491 | ||
a0d269ec TV |
4492 | cinfo = dsi->user_dsi_cinfo; |
4493 | ||
b6e695ab | 4494 | r = dsi_calc_clock_rates(dsidev, &cinfo); |
ebf0a3fe VS |
4495 | if (r) { |
4496 | DSSERR("Failed to calc dsi clocks\n"); | |
3de7a1dc | 4497 | return r; |
ebf0a3fe | 4498 | } |
3de7a1dc | 4499 | |
a72b64b9 | 4500 | r = dsi_pll_set_clock_div(dsidev, &cinfo); |
3de7a1dc TV |
4501 | if (r) { |
4502 | DSSERR("Failed to set dsi clocks\n"); | |
4503 | return r; | |
4504 | } | |
4505 | ||
4506 | return 0; | |
4507 | } | |
4508 | ||
5761217a | 4509 | static int dsi_display_init_dsi(struct platform_device *dsidev) |
3de7a1dc | 4510 | { |
11ee9606 | 4511 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
4512 | int r; |
4513 | ||
a72b64b9 | 4514 | r = dsi_pll_init(dsidev, true, true); |
3de7a1dc TV |
4515 | if (r) |
4516 | goto err0; | |
4517 | ||
5761217a | 4518 | r = dsi_configure_dsi_clocks(dsidev); |
3de7a1dc TV |
4519 | if (r) |
4520 | goto err1; | |
4521 | ||
4ce9e33c TV |
4522 | dss_select_dsi_clk_source(dsi->module_id, dsi->module_id == 0 ? |
4523 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : | |
4524 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI); | |
3de7a1dc TV |
4525 | |
4526 | DSSDBG("PLL OK\n"); | |
4527 | ||
9e7e9372 | 4528 | r = dsi_cio_init(dsidev); |
3de7a1dc TV |
4529 | if (r) |
4530 | goto err2; | |
4531 | ||
a72b64b9 | 4532 | _dsi_print_reset_status(dsidev); |
3de7a1dc | 4533 | |
9e7e9372 | 4534 | dsi_proto_timings(dsidev); |
5761217a | 4535 | dsi_set_lp_clk_divisor(dsidev); |
3de7a1dc TV |
4536 | |
4537 | if (1) | |
a72b64b9 | 4538 | _dsi_print_reset_status(dsidev); |
3de7a1dc | 4539 | |
5761217a | 4540 | r = dsi_proto_config(dsidev); |
3de7a1dc TV |
4541 | if (r) |
4542 | goto err3; | |
4543 | ||
4544 | /* enable interface */ | |
a72b64b9 AT |
4545 | dsi_vc_enable(dsidev, 0, 1); |
4546 | dsi_vc_enable(dsidev, 1, 1); | |
4547 | dsi_vc_enable(dsidev, 2, 1); | |
4548 | dsi_vc_enable(dsidev, 3, 1); | |
4549 | dsi_if_enable(dsidev, 1); | |
4550 | dsi_force_tx_stop_mode_io(dsidev); | |
3de7a1dc | 4551 | |
3de7a1dc | 4552 | return 0; |
3de7a1dc | 4553 | err3: |
9e7e9372 | 4554 | dsi_cio_uninit(dsidev); |
3de7a1dc | 4555 | err2: |
11ee9606 | 4556 | dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK); |
3de7a1dc | 4557 | err1: |
a72b64b9 | 4558 | dsi_pll_uninit(dsidev, true); |
3de7a1dc TV |
4559 | err0: |
4560 | return r; | |
4561 | } | |
4562 | ||
5761217a | 4563 | static void dsi_display_uninit_dsi(struct platform_device *dsidev, |
22d6d676 | 4564 | bool disconnect_lanes, bool enter_ulps) |
3de7a1dc | 4565 | { |
f1da39d9 | 4566 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
a72b64b9 | 4567 | |
f1da39d9 | 4568 | if (enter_ulps && !dsi->ulps_enabled) |
a72b64b9 | 4569 | dsi_enter_ulps(dsidev); |
40885ab3 | 4570 | |
d7370104 | 4571 | /* disable interface */ |
a72b64b9 AT |
4572 | dsi_if_enable(dsidev, 0); |
4573 | dsi_vc_enable(dsidev, 0, 0); | |
4574 | dsi_vc_enable(dsidev, 1, 0); | |
4575 | dsi_vc_enable(dsidev, 2, 0); | |
4576 | dsi_vc_enable(dsidev, 3, 0); | |
d7370104 | 4577 | |
11ee9606 | 4578 | dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK); |
9e7e9372 | 4579 | dsi_cio_uninit(dsidev); |
a72b64b9 | 4580 | dsi_pll_uninit(dsidev, disconnect_lanes); |
3de7a1dc TV |
4581 | } |
4582 | ||
37ac60e4 | 4583 | int omapdss_dsi_display_enable(struct omap_dss_device *dssdev) |
3de7a1dc | 4584 | { |
a72b64b9 | 4585 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
f1da39d9 | 4586 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
3de7a1dc TV |
4587 | int r = 0; |
4588 | ||
4589 | DSSDBG("dsi_display_enable\n"); | |
4590 | ||
a72b64b9 | 4591 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
37ac60e4 | 4592 | |
f1da39d9 | 4593 | mutex_lock(&dsi->lock); |
3de7a1dc | 4594 | |
4fbafaf3 | 4595 | r = dsi_runtime_get(dsidev); |
3de7a1dc | 4596 | if (r) |
4fbafaf3 TV |
4597 | goto err_get_dsi; |
4598 | ||
4599 | dsi_enable_pll_clock(dsidev, 1); | |
3de7a1dc | 4600 | |
4fbafaf3 | 4601 | _dsi_initialize_irq(dsidev); |
3de7a1dc | 4602 | |
5761217a | 4603 | r = dsi_display_init_dsi(dsidev); |
3de7a1dc | 4604 | if (r) |
4fbafaf3 | 4605 | goto err_init_dsi; |
3de7a1dc | 4606 | |
f1da39d9 | 4607 | mutex_unlock(&dsi->lock); |
3de7a1dc TV |
4608 | |
4609 | return 0; | |
4610 | ||
4fbafaf3 | 4611 | err_init_dsi: |
a72b64b9 | 4612 | dsi_enable_pll_clock(dsidev, 0); |
4fbafaf3 TV |
4613 | dsi_runtime_put(dsidev); |
4614 | err_get_dsi: | |
f1da39d9 | 4615 | mutex_unlock(&dsi->lock); |
3de7a1dc TV |
4616 | DSSDBG("dsi_display_enable FAILED\n"); |
4617 | return r; | |
4618 | } | |
37ac60e4 | 4619 | EXPORT_SYMBOL(omapdss_dsi_display_enable); |
3de7a1dc | 4620 | |
2a89dc15 | 4621 | void omapdss_dsi_display_disable(struct omap_dss_device *dssdev, |
22d6d676 | 4622 | bool disconnect_lanes, bool enter_ulps) |
3de7a1dc | 4623 | { |
a72b64b9 | 4624 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
f1da39d9 | 4625 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
a72b64b9 | 4626 | |
3de7a1dc TV |
4627 | DSSDBG("dsi_display_disable\n"); |
4628 | ||
a72b64b9 | 4629 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
3de7a1dc | 4630 | |
f1da39d9 | 4631 | mutex_lock(&dsi->lock); |
3de7a1dc | 4632 | |
15ffa1da TV |
4633 | dsi_sync_vc(dsidev, 0); |
4634 | dsi_sync_vc(dsidev, 1); | |
4635 | dsi_sync_vc(dsidev, 2); | |
4636 | dsi_sync_vc(dsidev, 3); | |
4637 | ||
5761217a | 4638 | dsi_display_uninit_dsi(dsidev, disconnect_lanes, enter_ulps); |
3de7a1dc | 4639 | |
4fbafaf3 | 4640 | dsi_runtime_put(dsidev); |
a72b64b9 | 4641 | dsi_enable_pll_clock(dsidev, 0); |
3de7a1dc | 4642 | |
f1da39d9 | 4643 | mutex_unlock(&dsi->lock); |
3de7a1dc | 4644 | } |
37ac60e4 | 4645 | EXPORT_SYMBOL(omapdss_dsi_display_disable); |
3de7a1dc | 4646 | |
225b650d | 4647 | int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable) |
3de7a1dc | 4648 | { |
f1da39d9 AT |
4649 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
4650 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
4651 | ||
4652 | dsi->te_enabled = enable; | |
225b650d | 4653 | return 0; |
3de7a1dc | 4654 | } |
225b650d | 4655 | EXPORT_SYMBOL(omapdss_dsi_enable_te); |
3de7a1dc | 4656 | |
f1e0001f TV |
4657 | #ifdef PRINT_VERBOSE_VM_TIMINGS |
4658 | static void print_dsi_vm(const char *str, | |
4659 | const struct omap_dss_dsi_videomode_timings *t) | |
4660 | { | |
4661 | unsigned long byteclk = t->hsclk / 4; | |
4662 | int bl, wc, pps, tot; | |
4663 | ||
4664 | wc = DIV_ROUND_UP(t->hact * t->bitspp, 8); | |
4665 | pps = DIV_ROUND_UP(wc + 6, t->ndl); /* pixel packet size */ | |
4666 | bl = t->hss + t->hsa + t->hse + t->hbp + t->hfp; | |
4667 | tot = bl + pps; | |
4668 | ||
4669 | #define TO_DSI_T(x) ((u32)div64_u64((u64)x * 1000000000llu, byteclk)) | |
4670 | ||
4671 | pr_debug("%s bck %lu, %u/%u/%u/%u/%u/%u = %u+%u = %u, " | |
4672 | "%u/%u/%u/%u/%u/%u = %u + %u = %u\n", | |
4673 | str, | |
4674 | byteclk, | |
4675 | t->hss, t->hsa, t->hse, t->hbp, pps, t->hfp, | |
4676 | bl, pps, tot, | |
4677 | TO_DSI_T(t->hss), | |
4678 | TO_DSI_T(t->hsa), | |
4679 | TO_DSI_T(t->hse), | |
4680 | TO_DSI_T(t->hbp), | |
4681 | TO_DSI_T(pps), | |
4682 | TO_DSI_T(t->hfp), | |
4683 | ||
4684 | TO_DSI_T(bl), | |
4685 | TO_DSI_T(pps), | |
4686 | ||
4687 | TO_DSI_T(tot)); | |
4688 | #undef TO_DSI_T | |
4689 | } | |
4690 | ||
4691 | static void print_dispc_vm(const char *str, const struct omap_video_timings *t) | |
4692 | { | |
4693 | unsigned long pck = t->pixel_clock * 1000; | |
4694 | int hact, bl, tot; | |
4695 | ||
4696 | hact = t->x_res; | |
4697 | bl = t->hsw + t->hbp + t->hfp; | |
4698 | tot = hact + bl; | |
4699 | ||
4700 | #define TO_DISPC_T(x) ((u32)div64_u64((u64)x * 1000000000llu, pck)) | |
4701 | ||
4702 | pr_debug("%s pck %lu, %u/%u/%u/%u = %u+%u = %u, " | |
4703 | "%u/%u/%u/%u = %u + %u = %u\n", | |
4704 | str, | |
4705 | pck, | |
4706 | t->hsw, t->hbp, hact, t->hfp, | |
4707 | bl, hact, tot, | |
4708 | TO_DISPC_T(t->hsw), | |
4709 | TO_DISPC_T(t->hbp), | |
4710 | TO_DISPC_T(hact), | |
4711 | TO_DISPC_T(t->hfp), | |
4712 | TO_DISPC_T(bl), | |
4713 | TO_DISPC_T(hact), | |
4714 | TO_DISPC_T(tot)); | |
4715 | #undef TO_DISPC_T | |
4716 | } | |
4717 | ||
4718 | /* note: this is not quite accurate */ | |
4719 | static void print_dsi_dispc_vm(const char *str, | |
4720 | const struct omap_dss_dsi_videomode_timings *t) | |
4721 | { | |
4722 | struct omap_video_timings vm = { 0 }; | |
4723 | unsigned long byteclk = t->hsclk / 4; | |
4724 | unsigned long pck; | |
4725 | u64 dsi_tput; | |
4726 | int dsi_hact, dsi_htot; | |
4727 | ||
4728 | dsi_tput = (u64)byteclk * t->ndl * 8; | |
4729 | pck = (u32)div64_u64(dsi_tput, t->bitspp); | |
4730 | dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(t->hact * t->bitspp, 8) + 6, t->ndl); | |
4731 | dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + t->hfp; | |
4732 | ||
4733 | vm.pixel_clock = pck / 1000; | |
4734 | vm.hsw = div64_u64((u64)(t->hsa + t->hse) * pck, byteclk); | |
4735 | vm.hbp = div64_u64((u64)t->hbp * pck, byteclk); | |
4736 | vm.hfp = div64_u64((u64)t->hfp * pck, byteclk); | |
4737 | vm.x_res = t->hact; | |
4738 | ||
4739 | print_dispc_vm(str, &vm); | |
4740 | } | |
4741 | #endif /* PRINT_VERBOSE_VM_TIMINGS */ | |
4742 | ||
4743 | static bool dsi_cm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, | |
4744 | unsigned long pck, void *data) | |
e67458a8 | 4745 | { |
f1e0001f TV |
4746 | struct dsi_clk_calc_ctx *ctx = data; |
4747 | struct omap_video_timings *t = &ctx->dispc_vm; | |
e67458a8 | 4748 | |
f1e0001f TV |
4749 | ctx->dispc_cinfo.lck_div = lckd; |
4750 | ctx->dispc_cinfo.pck_div = pckd; | |
4751 | ctx->dispc_cinfo.lck = lck; | |
4752 | ctx->dispc_cinfo.pck = pck; | |
e67458a8 | 4753 | |
f1e0001f TV |
4754 | *t = *ctx->config->timings; |
4755 | t->pixel_clock = pck / 1000; | |
4756 | t->x_res = ctx->config->timings->x_res; | |
4757 | t->y_res = ctx->config->timings->y_res; | |
4758 | t->hsw = t->hfp = t->hbp = t->vsw = 1; | |
4759 | t->vfp = t->vbp = 0; | |
e67458a8 | 4760 | |
f1e0001f | 4761 | return true; |
e67458a8 | 4762 | } |
e67458a8 | 4763 | |
f1e0001f TV |
4764 | static bool dsi_cm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, |
4765 | void *data) | |
e352574d | 4766 | { |
f1e0001f | 4767 | struct dsi_clk_calc_ctx *ctx = data; |
e352574d | 4768 | |
f1e0001f TV |
4769 | ctx->dsi_cinfo.regm_dispc = regm_dispc; |
4770 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; | |
e352574d | 4771 | |
f1e0001f TV |
4772 | return dispc_div_calc(dispc, ctx->req_pck_min, ctx->req_pck_max, |
4773 | dsi_cm_calc_dispc_cb, ctx); | |
4774 | } | |
e352574d | 4775 | |
f1e0001f TV |
4776 | static bool dsi_cm_calc_pll_cb(int regn, int regm, unsigned long fint, |
4777 | unsigned long pll, void *data) | |
4778 | { | |
4779 | struct dsi_clk_calc_ctx *ctx = data; | |
4780 | ||
4781 | ctx->dsi_cinfo.regn = regn; | |
4782 | ctx->dsi_cinfo.regm = regm; | |
4783 | ctx->dsi_cinfo.fint = fint; | |
4784 | ctx->dsi_cinfo.clkin4ddr = pll; | |
4785 | ||
4786 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min, | |
4787 | dsi_cm_calc_hsdiv_cb, ctx); | |
e352574d | 4788 | } |
e352574d | 4789 | |
f1e0001f TV |
4790 | static bool dsi_cm_calc(struct dsi_data *dsi, |
4791 | const struct omap_dss_dsi_config *cfg, | |
4792 | struct dsi_clk_calc_ctx *ctx) | |
02c3960b | 4793 | { |
f1e0001f TV |
4794 | unsigned long clkin; |
4795 | int bitspp, ndl; | |
4796 | unsigned long pll_min, pll_max; | |
4797 | unsigned long pck, txbyteclk; | |
02c3960b | 4798 | |
f1e0001f TV |
4799 | clkin = clk_get_rate(dsi->sys_clk); |
4800 | bitspp = dsi_get_pixel_size(cfg->pixel_format); | |
4801 | ndl = dsi->num_lanes_used - 1; | |
4802 | ||
4803 | /* | |
4804 | * Here we should calculate minimum txbyteclk to be able to send the | |
4805 | * frame in time, and also to handle TE. That's not very simple, though, | |
4806 | * especially as we go to LP between each pixel packet due to HW | |
4807 | * "feature". So let's just estimate very roughly and multiply by 1.5. | |
4808 | */ | |
4809 | pck = cfg->timings->pixel_clock * 1000; | |
4810 | pck = pck * 3 / 2; | |
4811 | txbyteclk = pck * bitspp / 8 / ndl; | |
02c3960b | 4812 | |
f1e0001f TV |
4813 | memset(ctx, 0, sizeof(*ctx)); |
4814 | ctx->dsidev = dsi->pdev; | |
4815 | ctx->config = cfg; | |
4816 | ctx->req_pck_min = pck; | |
4817 | ctx->req_pck_nom = pck; | |
4818 | ctx->req_pck_max = pck * 3 / 2; | |
4819 | ctx->dsi_cinfo.clkin = clkin; | |
02c3960b | 4820 | |
f1e0001f TV |
4821 | pll_min = max(cfg->hs_clk_min * 4, txbyteclk * 4 * 4); |
4822 | pll_max = cfg->hs_clk_max * 4; | |
4823 | ||
4824 | return dsi_pll_calc(dsi->pdev, clkin, | |
4825 | pll_min, pll_max, | |
4826 | dsi_cm_calc_pll_cb, ctx); | |
02c3960b | 4827 | } |
02c3960b | 4828 | |
f1e0001f | 4829 | static bool dsi_vm_calc_blanking(struct dsi_clk_calc_ctx *ctx) |
dca2b152 | 4830 | { |
f1e0001f TV |
4831 | struct dsi_data *dsi = dsi_get_dsidrv_data(ctx->dsidev); |
4832 | const struct omap_dss_dsi_config *cfg = ctx->config; | |
4833 | int bitspp = dsi_get_pixel_size(cfg->pixel_format); | |
4834 | int ndl = dsi->num_lanes_used - 1; | |
4835 | unsigned long hsclk = ctx->dsi_cinfo.clkin4ddr / 4; | |
4836 | unsigned long byteclk = hsclk / 4; | |
dca2b152 | 4837 | |
f1e0001f TV |
4838 | unsigned long dispc_pck, req_pck_min, req_pck_nom, req_pck_max; |
4839 | int xres; | |
4840 | int panel_htot, panel_hbl; /* pixels */ | |
4841 | int dispc_htot, dispc_hbl; /* pixels */ | |
4842 | int dsi_htot, dsi_hact, dsi_hbl, hss, hse; /* byteclks */ | |
4843 | int hfp, hsa, hbp; | |
4844 | const struct omap_video_timings *req_vm; | |
4845 | struct omap_video_timings *dispc_vm; | |
4846 | struct omap_dss_dsi_videomode_timings *dsi_vm; | |
4847 | u64 dsi_tput, dispc_tput; | |
dca2b152 | 4848 | |
f1e0001f | 4849 | dsi_tput = (u64)byteclk * ndl * 8; |
dca2b152 | 4850 | |
f1e0001f TV |
4851 | req_vm = cfg->timings; |
4852 | req_pck_min = ctx->req_pck_min; | |
4853 | req_pck_max = ctx->req_pck_max; | |
4854 | req_pck_nom = ctx->req_pck_nom; | |
4855 | ||
4856 | dispc_pck = ctx->dispc_cinfo.pck; | |
4857 | dispc_tput = (u64)dispc_pck * bitspp; | |
4858 | ||
4859 | xres = req_vm->x_res; | |
4860 | ||
4861 | panel_hbl = req_vm->hfp + req_vm->hbp + req_vm->hsw; | |
4862 | panel_htot = xres + panel_hbl; | |
4863 | ||
4864 | dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(xres * bitspp, 8) + 6, ndl); | |
4865 | ||
4866 | /* | |
4867 | * When there are no line buffers, DISPC and DSI must have the | |
4868 | * same tput. Otherwise DISPC tput needs to be higher than DSI's. | |
4869 | */ | |
4870 | if (dsi->line_buffer_size < xres * bitspp / 8) { | |
4871 | if (dispc_tput != dsi_tput) | |
4872 | return false; | |
4873 | } else { | |
4874 | if (dispc_tput < dsi_tput) | |
4875 | return false; | |
4876 | } | |
4877 | ||
4878 | /* DSI tput must be over the min requirement */ | |
4879 | if (dsi_tput < (u64)bitspp * req_pck_min) | |
4880 | return false; | |
4881 | ||
4882 | /* When non-burst mode, DSI tput must be below max requirement. */ | |
4883 | if (cfg->trans_mode != OMAP_DSS_DSI_BURST_MODE) { | |
4884 | if (dsi_tput > (u64)bitspp * req_pck_max) | |
4885 | return false; | |
4886 | } | |
4887 | ||
4888 | hss = DIV_ROUND_UP(4, ndl); | |
4889 | ||
4890 | if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { | |
4891 | if (ndl == 3 && req_vm->hsw == 0) | |
4892 | hse = 1; | |
4893 | else | |
4894 | hse = DIV_ROUND_UP(4, ndl); | |
4895 | } else { | |
4896 | hse = 0; | |
4897 | } | |
4898 | ||
4899 | /* DSI htot to match the panel's nominal pck */ | |
4900 | dsi_htot = div64_u64((u64)panel_htot * byteclk, req_pck_nom); | |
4901 | ||
4902 | /* fail if there would be no time for blanking */ | |
4903 | if (dsi_htot < hss + hse + dsi_hact) | |
4904 | return false; | |
4905 | ||
4906 | /* total DSI blanking needed to achieve panel's TL */ | |
4907 | dsi_hbl = dsi_htot - dsi_hact; | |
4908 | ||
4909 | /* DISPC htot to match the DSI TL */ | |
4910 | dispc_htot = div64_u64((u64)dsi_htot * dispc_pck, byteclk); | |
4911 | ||
4912 | /* verify that the DSI and DISPC TLs are the same */ | |
4913 | if ((u64)dsi_htot * dispc_pck != (u64)dispc_htot * byteclk) | |
4914 | return false; | |
4915 | ||
4916 | dispc_hbl = dispc_htot - xres; | |
4917 | ||
4918 | /* setup DSI videomode */ | |
4919 | ||
4920 | dsi_vm = &ctx->dsi_vm; | |
4921 | memset(dsi_vm, 0, sizeof(*dsi_vm)); | |
4922 | ||
4923 | dsi_vm->hsclk = hsclk; | |
4924 | ||
4925 | dsi_vm->ndl = ndl; | |
4926 | dsi_vm->bitspp = bitspp; | |
4927 | ||
4928 | if (cfg->trans_mode != OMAP_DSS_DSI_PULSE_MODE) { | |
4929 | hsa = 0; | |
4930 | } else if (ndl == 3 && req_vm->hsw == 0) { | |
4931 | hsa = 0; | |
4932 | } else { | |
4933 | hsa = div64_u64((u64)req_vm->hsw * byteclk, req_pck_nom); | |
4934 | hsa = max(hsa - hse, 1); | |
4935 | } | |
4936 | ||
4937 | hbp = div64_u64((u64)req_vm->hbp * byteclk, req_pck_nom); | |
4938 | hbp = max(hbp, 1); | |
4939 | ||
4940 | hfp = dsi_hbl - (hss + hsa + hse + hbp); | |
4941 | if (hfp < 1) { | |
4942 | int t; | |
4943 | /* we need to take cycles from hbp */ | |
4944 | ||
4945 | t = 1 - hfp; | |
4946 | hbp = max(hbp - t, 1); | |
4947 | hfp = dsi_hbl - (hss + hsa + hse + hbp); | |
4948 | ||
4949 | if (hfp < 1 && hsa > 0) { | |
4950 | /* we need to take cycles from hsa */ | |
4951 | t = 1 - hfp; | |
4952 | hsa = max(hsa - t, 1); | |
4953 | hfp = dsi_hbl - (hss + hsa + hse + hbp); | |
4954 | } | |
4955 | } | |
4956 | ||
4957 | if (hfp < 1) | |
4958 | return false; | |
4959 | ||
4960 | dsi_vm->hss = hss; | |
4961 | dsi_vm->hsa = hsa; | |
4962 | dsi_vm->hse = hse; | |
4963 | dsi_vm->hbp = hbp; | |
4964 | dsi_vm->hact = xres; | |
4965 | dsi_vm->hfp = hfp; | |
4966 | ||
4967 | dsi_vm->vsa = req_vm->vsw; | |
4968 | dsi_vm->vbp = req_vm->vbp; | |
4969 | dsi_vm->vact = req_vm->y_res; | |
4970 | dsi_vm->vfp = req_vm->vfp; | |
4971 | ||
4972 | dsi_vm->trans_mode = cfg->trans_mode; | |
4973 | ||
4974 | dsi_vm->blanking_mode = 0; | |
4975 | dsi_vm->hsa_blanking_mode = 1; | |
4976 | dsi_vm->hfp_blanking_mode = 1; | |
4977 | dsi_vm->hbp_blanking_mode = 1; | |
4978 | ||
4979 | dsi_vm->ddr_clk_always_on = cfg->ddr_clk_always_on; | |
4980 | dsi_vm->window_sync = 4; | |
4981 | ||
4982 | /* setup DISPC videomode */ | |
4983 | ||
4984 | dispc_vm = &ctx->dispc_vm; | |
4985 | *dispc_vm = *req_vm; | |
4986 | dispc_vm->pixel_clock = dispc_pck / 1000; | |
4987 | ||
4988 | if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { | |
4989 | hsa = div64_u64((u64)req_vm->hsw * dispc_pck, | |
4990 | req_pck_nom); | |
4991 | hsa = max(hsa, 1); | |
4992 | } else { | |
4993 | hsa = 1; | |
4994 | } | |
4995 | ||
4996 | hbp = div64_u64((u64)req_vm->hbp * dispc_pck, req_pck_nom); | |
4997 | hbp = max(hbp, 1); | |
4998 | ||
4999 | hfp = dispc_hbl - hsa - hbp; | |
5000 | if (hfp < 1) { | |
5001 | int t; | |
5002 | /* we need to take cycles from hbp */ | |
5003 | ||
5004 | t = 1 - hfp; | |
5005 | hbp = max(hbp - t, 1); | |
5006 | hfp = dispc_hbl - hsa - hbp; | |
5007 | ||
5008 | if (hfp < 1) { | |
5009 | /* we need to take cycles from hsa */ | |
5010 | t = 1 - hfp; | |
5011 | hsa = max(hsa - t, 1); | |
5012 | hfp = dispc_hbl - hsa - hbp; | |
5013 | } | |
5014 | } | |
5015 | ||
5016 | if (hfp < 1) | |
5017 | return false; | |
5018 | ||
5019 | dispc_vm->hfp = hfp; | |
5020 | dispc_vm->hsw = hsa; | |
5021 | dispc_vm->hbp = hbp; | |
5022 | ||
5023 | return true; | |
5024 | } | |
5025 | ||
5026 | ||
5027 | static bool dsi_vm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, | |
5028 | unsigned long pck, void *data) | |
5029 | { | |
5030 | struct dsi_clk_calc_ctx *ctx = data; | |
5031 | ||
5032 | ctx->dispc_cinfo.lck_div = lckd; | |
5033 | ctx->dispc_cinfo.pck_div = pckd; | |
5034 | ctx->dispc_cinfo.lck = lck; | |
5035 | ctx->dispc_cinfo.pck = pck; | |
5036 | ||
5037 | if (dsi_vm_calc_blanking(ctx) == false) | |
5038 | return false; | |
5039 | ||
5040 | #ifdef PRINT_VERBOSE_VM_TIMINGS | |
5041 | print_dispc_vm("dispc", &ctx->dispc_vm); | |
5042 | print_dsi_vm("dsi ", &ctx->dsi_vm); | |
5043 | print_dispc_vm("req ", ctx->config->timings); | |
5044 | print_dsi_dispc_vm("act ", &ctx->dsi_vm); | |
5045 | #endif | |
5046 | ||
5047 | return true; | |
5048 | } | |
5049 | ||
5050 | static bool dsi_vm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, | |
5051 | void *data) | |
5052 | { | |
5053 | struct dsi_clk_calc_ctx *ctx = data; | |
5054 | unsigned long pck_max; | |
5055 | ||
5056 | ctx->dsi_cinfo.regm_dispc = regm_dispc; | |
5057 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; | |
5058 | ||
5059 | /* | |
5060 | * In burst mode we can let the dispc pck be arbitrarily high, but it | |
5061 | * limits our scaling abilities. So for now, don't aim too high. | |
5062 | */ | |
5063 | ||
5064 | if (ctx->config->trans_mode == OMAP_DSS_DSI_BURST_MODE) | |
5065 | pck_max = ctx->req_pck_max + 10000000; | |
5066 | else | |
5067 | pck_max = ctx->req_pck_max; | |
5068 | ||
5069 | return dispc_div_calc(dispc, ctx->req_pck_min, pck_max, | |
5070 | dsi_vm_calc_dispc_cb, ctx); | |
5071 | } | |
5072 | ||
5073 | static bool dsi_vm_calc_pll_cb(int regn, int regm, unsigned long fint, | |
5074 | unsigned long pll, void *data) | |
5075 | { | |
5076 | struct dsi_clk_calc_ctx *ctx = data; | |
5077 | ||
5078 | ctx->dsi_cinfo.regn = regn; | |
5079 | ctx->dsi_cinfo.regm = regm; | |
5080 | ctx->dsi_cinfo.fint = fint; | |
5081 | ctx->dsi_cinfo.clkin4ddr = pll; | |
5082 | ||
5083 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min, | |
5084 | dsi_vm_calc_hsdiv_cb, ctx); | |
5085 | } | |
5086 | ||
5087 | static bool dsi_vm_calc(struct dsi_data *dsi, | |
5088 | const struct omap_dss_dsi_config *cfg, | |
5089 | struct dsi_clk_calc_ctx *ctx) | |
5090 | { | |
5091 | const struct omap_video_timings *t = cfg->timings; | |
5092 | unsigned long clkin; | |
5093 | unsigned long pll_min; | |
5094 | unsigned long pll_max; | |
5095 | int ndl = dsi->num_lanes_used - 1; | |
5096 | int bitspp = dsi_get_pixel_size(cfg->pixel_format); | |
5097 | unsigned long byteclk_min; | |
5098 | ||
5099 | clkin = clk_get_rate(dsi->sys_clk); | |
5100 | ||
5101 | memset(ctx, 0, sizeof(*ctx)); | |
5102 | ctx->dsidev = dsi->pdev; | |
5103 | ctx->config = cfg; | |
5104 | ||
5105 | ctx->dsi_cinfo.clkin = clkin; | |
5106 | ||
5107 | /* these limits should come from the panel driver */ | |
5108 | ctx->req_pck_min = t->pixel_clock * 1000 - 1000; | |
5109 | ctx->req_pck_nom = t->pixel_clock * 1000; | |
5110 | ctx->req_pck_max = t->pixel_clock * 1000 + 1000; | |
5111 | ||
5112 | byteclk_min = div64_u64((u64)ctx->req_pck_min * bitspp, ndl * 8); | |
5113 | pll_min = max(cfg->hs_clk_min * 4, byteclk_min * 4 * 4); | |
5114 | ||
5115 | if (cfg->trans_mode == OMAP_DSS_DSI_BURST_MODE) { | |
5116 | pll_max = cfg->hs_clk_max * 4; | |
5117 | } else { | |
5118 | unsigned long byteclk_max; | |
5119 | byteclk_max = div64_u64((u64)ctx->req_pck_max * bitspp, | |
5120 | ndl * 8); | |
5121 | ||
5122 | pll_max = byteclk_max * 4 * 4; | |
5123 | } | |
5124 | ||
5125 | return dsi_pll_calc(dsi->pdev, clkin, | |
5126 | pll_min, pll_max, | |
5127 | dsi_vm_calc_pll_cb, ctx); | |
dca2b152 | 5128 | } |
dca2b152 | 5129 | |
777f05cc TV |
5130 | int omapdss_dsi_set_config(struct omap_dss_device *dssdev, |
5131 | const struct omap_dss_dsi_config *config) | |
0b3ffe39 AT |
5132 | { |
5133 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); | |
5134 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
f1e0001f TV |
5135 | struct dsi_clk_calc_ctx ctx; |
5136 | bool ok; | |
5137 | int r; | |
0b3ffe39 AT |
5138 | |
5139 | mutex_lock(&dsi->lock); | |
5140 | ||
777f05cc TV |
5141 | dsi->pix_fmt = config->pixel_format; |
5142 | dsi->mode = config->mode; | |
e352574d | 5143 | |
f1e0001f TV |
5144 | if (config->mode == OMAP_DSS_DSI_VIDEO_MODE) |
5145 | ok = dsi_vm_calc(dsi, config, &ctx); | |
5146 | else | |
5147 | ok = dsi_cm_calc(dsi, config, &ctx); | |
5148 | ||
5149 | if (!ok) { | |
5150 | DSSERR("failed to find suitable DSI clock settings\n"); | |
5151 | r = -EINVAL; | |
5152 | goto err; | |
5153 | } | |
5154 | ||
5155 | dsi_pll_calc_dsi_fck(&ctx.dsi_cinfo); | |
5156 | ||
5157 | r = dsi_lp_clock_calc(&ctx.dsi_cinfo, config->lp_clk_min, | |
5158 | config->lp_clk_max); | |
5159 | if (r) { | |
5160 | DSSERR("failed to find suitable DSI LP clock settings\n"); | |
5161 | goto err; | |
5162 | } | |
5163 | ||
5164 | dsi->user_dsi_cinfo = ctx.dsi_cinfo; | |
5165 | dsi->user_dispc_cinfo = ctx.dispc_cinfo; | |
5166 | ||
5167 | dsi->timings = ctx.dispc_vm; | |
5168 | dsi->vm_timings = ctx.dsi_vm; | |
0b3ffe39 AT |
5169 | |
5170 | mutex_unlock(&dsi->lock); | |
e352574d | 5171 | |
777f05cc | 5172 | return 0; |
f1e0001f TV |
5173 | err: |
5174 | mutex_unlock(&dsi->lock); | |
5175 | ||
5176 | return r; | |
0b3ffe39 | 5177 | } |
777f05cc | 5178 | EXPORT_SYMBOL(omapdss_dsi_set_config); |
0b3ffe39 | 5179 | |
2eea5ae6 TV |
5180 | /* |
5181 | * Return a hardcoded channel for the DSI output. This should work for | |
5182 | * current use cases, but this can be later expanded to either resolve | |
5183 | * the channel in some more dynamic manner, or get the channel as a user | |
5184 | * parameter. | |
5185 | */ | |
5186 | static enum omap_channel dsi_get_channel(int module_id) | |
5187 | { | |
5188 | switch (omapdss_get_version()) { | |
5189 | case OMAPDSS_VER_OMAP24xx: | |
5190 | DSSWARN("DSI not supported\n"); | |
5191 | return OMAP_DSS_CHANNEL_LCD; | |
5192 | ||
5193 | case OMAPDSS_VER_OMAP34xx_ES1: | |
5194 | case OMAPDSS_VER_OMAP34xx_ES3: | |
5195 | case OMAPDSS_VER_OMAP3630: | |
5196 | case OMAPDSS_VER_AM35xx: | |
5197 | return OMAP_DSS_CHANNEL_LCD; | |
5198 | ||
5199 | case OMAPDSS_VER_OMAP4430_ES1: | |
5200 | case OMAPDSS_VER_OMAP4430_ES2: | |
5201 | case OMAPDSS_VER_OMAP4: | |
5202 | switch (module_id) { | |
5203 | case 0: | |
5204 | return OMAP_DSS_CHANNEL_LCD; | |
5205 | case 1: | |
5206 | return OMAP_DSS_CHANNEL_LCD2; | |
5207 | default: | |
5208 | DSSWARN("unsupported module id\n"); | |
5209 | return OMAP_DSS_CHANNEL_LCD; | |
5210 | } | |
5211 | ||
5212 | case OMAPDSS_VER_OMAP5: | |
5213 | switch (module_id) { | |
5214 | case 0: | |
5215 | return OMAP_DSS_CHANNEL_LCD; | |
5216 | case 1: | |
5217 | return OMAP_DSS_CHANNEL_LCD3; | |
5218 | default: | |
5219 | DSSWARN("unsupported module id\n"); | |
5220 | return OMAP_DSS_CHANNEL_LCD; | |
5221 | } | |
5222 | ||
5223 | default: | |
5224 | DSSWARN("unsupported DSS version\n"); | |
5225 | return OMAP_DSS_CHANNEL_LCD; | |
5226 | } | |
0b3ffe39 | 5227 | } |
0b3ffe39 | 5228 | |
5ee3c144 AT |
5229 | int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel) |
5230 | { | |
f1da39d9 AT |
5231 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
5232 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
5ee3c144 AT |
5233 | int i; |
5234 | ||
f1da39d9 AT |
5235 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
5236 | if (!dsi->vc[i].dssdev) { | |
5237 | dsi->vc[i].dssdev = dssdev; | |
5ee3c144 AT |
5238 | *channel = i; |
5239 | return 0; | |
5240 | } | |
5241 | } | |
5242 | ||
5243 | DSSERR("cannot get VC for display %s", dssdev->name); | |
5244 | return -ENOSPC; | |
5245 | } | |
5246 | EXPORT_SYMBOL(omap_dsi_request_vc); | |
5247 | ||
5248 | int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id) | |
5249 | { | |
f1da39d9 AT |
5250 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
5251 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
5252 | ||
5ee3c144 AT |
5253 | if (vc_id < 0 || vc_id > 3) { |
5254 | DSSERR("VC ID out of range\n"); | |
5255 | return -EINVAL; | |
5256 | } | |
5257 | ||
5258 | if (channel < 0 || channel > 3) { | |
5259 | DSSERR("Virtual Channel out of range\n"); | |
5260 | return -EINVAL; | |
5261 | } | |
5262 | ||
f1da39d9 | 5263 | if (dsi->vc[channel].dssdev != dssdev) { |
5ee3c144 AT |
5264 | DSSERR("Virtual Channel not allocated to display %s\n", |
5265 | dssdev->name); | |
5266 | return -EINVAL; | |
5267 | } | |
5268 | ||
f1da39d9 | 5269 | dsi->vc[channel].vc_id = vc_id; |
5ee3c144 AT |
5270 | |
5271 | return 0; | |
5272 | } | |
5273 | EXPORT_SYMBOL(omap_dsi_set_vc_id); | |
5274 | ||
5275 | void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel) | |
5276 | { | |
f1da39d9 AT |
5277 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
5278 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
5279 | ||
5ee3c144 | 5280 | if ((channel >= 0 && channel <= 3) && |
f1da39d9 AT |
5281 | dsi->vc[channel].dssdev == dssdev) { |
5282 | dsi->vc[channel].dssdev = NULL; | |
5283 | dsi->vc[channel].vc_id = 0; | |
5ee3c144 AT |
5284 | } |
5285 | } | |
5286 | EXPORT_SYMBOL(omap_dsi_release_vc); | |
5287 | ||
a72b64b9 | 5288 | void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev) |
e406f907 | 5289 | { |
a72b64b9 | 5290 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1) |
067a57e4 | 5291 | DSSERR("%s (%s) not active\n", |
89a35e51 AT |
5292 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
5293 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC)); | |
e406f907 TV |
5294 | } |
5295 | ||
a72b64b9 | 5296 | void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev) |
e406f907 | 5297 | { |
a72b64b9 | 5298 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1) |
067a57e4 | 5299 | DSSERR("%s (%s) not active\n", |
89a35e51 AT |
5300 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
5301 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI)); | |
e406f907 TV |
5302 | } |
5303 | ||
a72b64b9 | 5304 | static void dsi_calc_clock_param_ranges(struct platform_device *dsidev) |
49641116 | 5305 | { |
f1da39d9 AT |
5306 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
5307 | ||
5308 | dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN); | |
5309 | dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM); | |
5310 | dsi->regm_dispc_max = | |
5311 | dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC); | |
5312 | dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI); | |
5313 | dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT); | |
5314 | dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT); | |
5315 | dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV); | |
49641116 TA |
5316 | } |
5317 | ||
4fbafaf3 TV |
5318 | static int dsi_get_clocks(struct platform_device *dsidev) |
5319 | { | |
5320 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
5321 | struct clk *clk; | |
5322 | ||
5303b3aa | 5323 | clk = devm_clk_get(&dsidev->dev, "fck"); |
4fbafaf3 TV |
5324 | if (IS_ERR(clk)) { |
5325 | DSSERR("can't get fck\n"); | |
5326 | return PTR_ERR(clk); | |
5327 | } | |
5328 | ||
5329 | dsi->dss_clk = clk; | |
5330 | ||
5303b3aa | 5331 | clk = devm_clk_get(&dsidev->dev, "sys_clk"); |
4fbafaf3 TV |
5332 | if (IS_ERR(clk)) { |
5333 | DSSERR("can't get sys_clk\n"); | |
4fbafaf3 TV |
5334 | return PTR_ERR(clk); |
5335 | } | |
5336 | ||
5337 | dsi->sys_clk = clk; | |
5338 | ||
5339 | return 0; | |
5340 | } | |
5341 | ||
ee4a24e2 | 5342 | static struct omap_dss_device *dsi_find_dssdev(struct platform_device *pdev) |
38f3daf6 | 5343 | { |
1521653c TV |
5344 | struct omap_dss_board_info *pdata = pdev->dev.platform_data; |
5345 | struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); | |
2bbcce5e | 5346 | const char *def_disp_name = omapdss_get_default_display_name(); |
1521653c TV |
5347 | struct omap_dss_device *def_dssdev; |
5348 | int i; | |
5349 | ||
5350 | def_dssdev = NULL; | |
38f3daf6 TV |
5351 | |
5352 | for (i = 0; i < pdata->num_devices; ++i) { | |
5353 | struct omap_dss_device *dssdev = pdata->devices[i]; | |
5354 | ||
5355 | if (dssdev->type != OMAP_DISPLAY_TYPE_DSI) | |
5356 | continue; | |
5357 | ||
5358 | if (dssdev->phy.dsi.module != dsi->module_id) | |
5359 | continue; | |
5360 | ||
1521653c TV |
5361 | if (def_dssdev == NULL) |
5362 | def_dssdev = dssdev; | |
5363 | ||
5364 | if (def_disp_name != NULL && | |
5365 | strcmp(dssdev->name, def_disp_name) == 0) { | |
5366 | def_dssdev = dssdev; | |
5367 | break; | |
38f3daf6 | 5368 | } |
1521653c | 5369 | } |
38f3daf6 | 5370 | |
1521653c TV |
5371 | return def_dssdev; |
5372 | } | |
5373 | ||
d1890a68 | 5374 | static int dsi_probe_pdata(struct platform_device *dsidev) |
1521653c | 5375 | { |
486c0e17 | 5376 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
5274484b | 5377 | struct omap_dss_device *plat_dssdev; |
1521653c TV |
5378 | struct omap_dss_device *dssdev; |
5379 | int r; | |
5380 | ||
5274484b | 5381 | plat_dssdev = dsi_find_dssdev(dsidev); |
1521653c | 5382 | |
5274484b | 5383 | if (!plat_dssdev) |
d1890a68 | 5384 | return 0; |
5274484b | 5385 | |
b2541c40 TV |
5386 | r = dsi_regulator_init(dsidev); |
5387 | if (r) | |
5388 | return r; | |
5389 | ||
5274484b | 5390 | dssdev = dss_alloc_and_init_device(&dsidev->dev); |
1521653c | 5391 | if (!dssdev) |
d1890a68 | 5392 | return -ENOMEM; |
1521653c | 5393 | |
5274484b TV |
5394 | dss_copy_device_pdata(dssdev, plat_dssdev); |
5395 | ||
486c0e17 TV |
5396 | r = omapdss_output_set_device(&dsi->output, dssdev); |
5397 | if (r) { | |
5398 | DSSERR("failed to connect output to new device: %s\n", | |
5399 | dssdev->name); | |
5400 | dss_put_device(dssdev); | |
d1890a68 | 5401 | return r; |
486c0e17 TV |
5402 | } |
5403 | ||
5274484b | 5404 | r = dss_add_device(dssdev); |
1521653c TV |
5405 | if (r) { |
5406 | DSSERR("device %s register failed: %d\n", dssdev->name, r); | |
486c0e17 | 5407 | omapdss_output_unset_device(&dsi->output); |
5274484b | 5408 | dss_put_device(dssdev); |
ee4a24e2 | 5409 | return r; |
38f3daf6 | 5410 | } |
ee4a24e2 TV |
5411 | |
5412 | return 0; | |
38f3daf6 TV |
5413 | } |
5414 | ||
ee4a24e2 | 5415 | static void dsi_init_output(struct platform_device *dsidev) |
81b87f51 AT |
5416 | { |
5417 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1f68d9c4 | 5418 | struct omap_dss_device *out = &dsi->output; |
81b87f51 | 5419 | |
1f68d9c4 | 5420 | out->dev = &dsidev->dev; |
81b87f51 AT |
5421 | out->id = dsi->module_id == 0 ? |
5422 | OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2; | |
5423 | ||
1f68d9c4 | 5424 | out->output_type = OMAP_DISPLAY_TYPE_DSI; |
7286a08f | 5425 | out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1"; |
2eea5ae6 | 5426 | out->dispc_channel = dsi_get_channel(dsi->module_id); |
b7328e14 | 5427 | out->owner = THIS_MODULE; |
81b87f51 | 5428 | |
5d47dbc8 | 5429 | omapdss_register_output(out); |
81b87f51 AT |
5430 | } |
5431 | ||
d1890a68 | 5432 | static void dsi_uninit_output(struct platform_device *dsidev) |
81b87f51 AT |
5433 | { |
5434 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); | |
1f68d9c4 | 5435 | struct omap_dss_device *out = &dsi->output; |
81b87f51 | 5436 | |
5d47dbc8 | 5437 | omapdss_unregister_output(out); |
81b87f51 AT |
5438 | } |
5439 | ||
b98482ed | 5440 | /* DSI1 HW IP initialisation */ |
ee4a24e2 | 5441 | static int omap_dsihw_probe(struct platform_device *dsidev) |
3de7a1dc TV |
5442 | { |
5443 | u32 rev; | |
11ee9606 | 5444 | int r, i; |
ea9da36a | 5445 | struct resource *dsi_mem; |
f1da39d9 AT |
5446 | struct dsi_data *dsi; |
5447 | ||
6e2a14d2 | 5448 | dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL); |
cd3b3449 TV |
5449 | if (!dsi) |
5450 | return -ENOMEM; | |
3de7a1dc | 5451 | |
11ee9606 | 5452 | dsi->module_id = dsidev->id; |
f1da39d9 | 5453 | dsi->pdev = dsidev; |
f1da39d9 | 5454 | dev_set_drvdata(&dsidev->dev, dsi); |
a72b64b9 | 5455 | |
f1da39d9 AT |
5456 | spin_lock_init(&dsi->irq_lock); |
5457 | spin_lock_init(&dsi->errors_lock); | |
5458 | dsi->errors = 0; | |
3de7a1dc | 5459 | |
dfc0fd8d | 5460 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
f1da39d9 AT |
5461 | spin_lock_init(&dsi->irq_stats_lock); |
5462 | dsi->irq_stats.last_reset = jiffies; | |
dfc0fd8d TV |
5463 | #endif |
5464 | ||
f1da39d9 AT |
5465 | mutex_init(&dsi->lock); |
5466 | sema_init(&dsi->bus_lock, 1); | |
3de7a1dc | 5467 | |
203b42f7 TH |
5468 | INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work, |
5469 | dsi_framedone_timeout_work_callback); | |
18946f62 | 5470 | |
3de7a1dc | 5471 | #ifdef DSI_CATCH_MISSING_TE |
f1da39d9 AT |
5472 | init_timer(&dsi->te_timer); |
5473 | dsi->te_timer.function = dsi_te_timeout; | |
5474 | dsi->te_timer.data = 0; | |
3de7a1dc | 5475 | #endif |
f1da39d9 | 5476 | dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0); |
ea9da36a SG |
5477 | if (!dsi_mem) { |
5478 | DSSERR("can't get IORESOURCE_MEM DSI\n"); | |
cd3b3449 | 5479 | return -EINVAL; |
ea9da36a | 5480 | } |
cd3b3449 | 5481 | |
6e2a14d2 JL |
5482 | dsi->base = devm_ioremap(&dsidev->dev, dsi_mem->start, |
5483 | resource_size(dsi_mem)); | |
f1da39d9 | 5484 | if (!dsi->base) { |
3de7a1dc | 5485 | DSSERR("can't ioremap DSI\n"); |
cd3b3449 | 5486 | return -ENOMEM; |
3de7a1dc | 5487 | } |
cd3b3449 | 5488 | |
f1da39d9 AT |
5489 | dsi->irq = platform_get_irq(dsi->pdev, 0); |
5490 | if (dsi->irq < 0) { | |
affe360d | 5491 | DSSERR("platform_get_irq failed\n"); |
cd3b3449 | 5492 | return -ENODEV; |
affe360d | 5493 | } |
5494 | ||
6e2a14d2 JL |
5495 | r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler, |
5496 | IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev); | |
affe360d | 5497 | if (r < 0) { |
5498 | DSSERR("request_irq failed\n"); | |
cd3b3449 | 5499 | return r; |
affe360d | 5500 | } |
3de7a1dc | 5501 | |
5ee3c144 | 5502 | /* DSI VCs initialization */ |
f1da39d9 | 5503 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
d6049144 | 5504 | dsi->vc[i].source = DSI_VC_SOURCE_L4; |
f1da39d9 AT |
5505 | dsi->vc[i].dssdev = NULL; |
5506 | dsi->vc[i].vc_id = 0; | |
5ee3c144 AT |
5507 | } |
5508 | ||
a72b64b9 | 5509 | dsi_calc_clock_param_ranges(dsidev); |
49641116 | 5510 | |
cd3b3449 TV |
5511 | r = dsi_get_clocks(dsidev); |
5512 | if (r) | |
5513 | return r; | |
5514 | ||
5515 | pm_runtime_enable(&dsidev->dev); | |
5516 | ||
4fbafaf3 TV |
5517 | r = dsi_runtime_get(dsidev); |
5518 | if (r) | |
cd3b3449 | 5519 | goto err_runtime_get; |
3de7a1dc | 5520 | |
a72b64b9 AT |
5521 | rev = dsi_read_reg(dsidev, DSI_REVISION); |
5522 | dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n", | |
3de7a1dc TV |
5523 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
5524 | ||
d9820850 TV |
5525 | /* DSI on OMAP3 doesn't have register DSI_GNQ, set number |
5526 | * of data to 3 by default */ | |
5527 | if (dss_has_feature(FEAT_DSI_GNQ)) | |
5528 | /* NB_DATA_LANES */ | |
5529 | dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9); | |
5530 | else | |
5531 | dsi->num_lanes_supported = 3; | |
75d7247c | 5532 | |
99322577 TV |
5533 | dsi->line_buffer_size = dsi_get_line_buf_size(dsidev); |
5534 | ||
81b87f51 AT |
5535 | dsi_init_output(dsidev); |
5536 | ||
c6ca5b22 TV |
5537 | if (dsidev->dev.platform_data) { |
5538 | r = dsi_probe_pdata(dsidev); | |
5539 | if (r) | |
5540 | goto err_probe; | |
d1890a68 | 5541 | } |
35deca3d | 5542 | |
4fbafaf3 | 5543 | dsi_runtime_put(dsidev); |
3de7a1dc | 5544 | |
11ee9606 | 5545 | if (dsi->module_id == 0) |
e40402cf | 5546 | dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs); |
11ee9606 | 5547 | else if (dsi->module_id == 1) |
e40402cf TV |
5548 | dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs); |
5549 | ||
5550 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS | |
11ee9606 | 5551 | if (dsi->module_id == 0) |
e40402cf | 5552 | dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs); |
11ee9606 | 5553 | else if (dsi->module_id == 1) |
e40402cf TV |
5554 | dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs); |
5555 | #endif | |
3de7a1dc | 5556 | return 0; |
4fbafaf3 | 5557 | |
c6ca5b22 TV |
5558 | err_probe: |
5559 | dsi_runtime_put(dsidev); | |
5560 | dsi_uninit_output(dsidev); | |
cd3b3449 | 5561 | err_runtime_get: |
4fbafaf3 | 5562 | pm_runtime_disable(&dsidev->dev); |
3de7a1dc TV |
5563 | return r; |
5564 | } | |
5565 | ||
6e7e8f06 | 5566 | static int __exit omap_dsihw_remove(struct platform_device *dsidev) |
3de7a1dc | 5567 | { |
f1da39d9 AT |
5568 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
5569 | ||
b98482ed TV |
5570 | WARN_ON(dsi->scp_clk_refcount > 0); |
5571 | ||
5274484b | 5572 | dss_unregister_child_devices(&dsidev->dev); |
35deca3d | 5573 | |
81b87f51 AT |
5574 | dsi_uninit_output(dsidev); |
5575 | ||
4fbafaf3 TV |
5576 | pm_runtime_disable(&dsidev->dev); |
5577 | ||
b2541c40 TV |
5578 | if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) { |
5579 | regulator_disable(dsi->vdds_dsi_reg); | |
5580 | dsi->vdds_dsi_enabled = false; | |
c8aac01b SG |
5581 | } |
5582 | ||
c8aac01b SG |
5583 | return 0; |
5584 | } | |
5585 | ||
4fbafaf3 TV |
5586 | static int dsi_runtime_suspend(struct device *dev) |
5587 | { | |
4fbafaf3 | 5588 | dispc_runtime_put(); |
4fbafaf3 TV |
5589 | |
5590 | return 0; | |
5591 | } | |
5592 | ||
5593 | static int dsi_runtime_resume(struct device *dev) | |
5594 | { | |
4fbafaf3 TV |
5595 | int r; |
5596 | ||
4fbafaf3 TV |
5597 | r = dispc_runtime_get(); |
5598 | if (r) | |
852f0838 | 5599 | return r; |
4fbafaf3 | 5600 | |
4fbafaf3 | 5601 | return 0; |
4fbafaf3 TV |
5602 | } |
5603 | ||
5604 | static const struct dev_pm_ops dsi_pm_ops = { | |
5605 | .runtime_suspend = dsi_runtime_suspend, | |
5606 | .runtime_resume = dsi_runtime_resume, | |
5607 | }; | |
5608 | ||
7c68dd96 | 5609 | static struct platform_driver omap_dsihw_driver = { |
ee4a24e2 | 5610 | .probe = omap_dsihw_probe, |
6e7e8f06 | 5611 | .remove = __exit_p(omap_dsihw_remove), |
c8aac01b | 5612 | .driver = { |
7c68dd96 | 5613 | .name = "omapdss_dsi", |
c8aac01b | 5614 | .owner = THIS_MODULE, |
4fbafaf3 | 5615 | .pm = &dsi_pm_ops, |
c8aac01b SG |
5616 | }, |
5617 | }; | |
5618 | ||
6e7e8f06 | 5619 | int __init dsi_init_platform_driver(void) |
c8aac01b | 5620 | { |
ee4a24e2 | 5621 | return platform_driver_register(&omap_dsihw_driver); |
c8aac01b SG |
5622 | } |
5623 | ||
6e7e8f06 | 5624 | void __exit dsi_uninit_platform_driver(void) |
c8aac01b | 5625 | { |
04c742c3 | 5626 | platform_driver_unregister(&omap_dsihw_driver); |
c8aac01b | 5627 | } |