blob: 0ca8ca3775fd6ffa300d45c6f627960f1e92f297 [file] [log] [blame]
Thierry Redingdec72732013-09-03 08:45:46 +02001/*
2 * Copyright (C) 2013 NVIDIA Corporation
3 *
Thierry Reding9a2ac2d2014-02-11 15:52:01 +01004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
Thierry Redingdec72732013-09-03 08:45:46 +02007 */
8
9#include <linux/clk.h>
10#include <linux/debugfs.h>
11#include <linux/host1x.h>
12#include <linux/module.h>
13#include <linux/of.h>
Thierry Redinge94236c2014-10-07 16:10:24 +020014#include <linux/of_platform.h>
Thierry Redingdec72732013-09-03 08:45:46 +020015#include <linux/platform_device.h>
16#include <linux/reset.h>
17
Thierry Reding3b077af2014-03-14 14:07:50 +010018#include <linux/regulator/consumer.h>
19
Thierry Redingdec72732013-09-03 08:45:46 +020020#include <drm/drm_mipi_dsi.h>
21#include <drm/drm_panel.h>
22
23#include <video/mipi_display.h>
24
25#include "dc.h"
26#include "drm.h"
27#include "dsi.h"
28#include "mipi-phy.h"
29
Thierry Redingdec72732013-09-03 08:45:46 +020030struct tegra_dsi {
31 struct host1x_client client;
32 struct tegra_output output;
33 struct device *dev;
34
35 void __iomem *regs;
36
37 struct reset_control *rst;
38 struct clk *clk_parent;
39 struct clk *clk_lp;
40 struct clk *clk;
41
42 struct drm_info_list *debugfs_files;
43 struct drm_minor *minor;
44 struct dentry *debugfs;
45
Thierry Reding17297a22014-03-14 14:13:15 +010046 unsigned long flags;
Thierry Redingdec72732013-09-03 08:45:46 +020047 enum mipi_dsi_pixel_format format;
48 unsigned int lanes;
49
50 struct tegra_mipi_device *mipi;
51 struct mipi_dsi_host host;
Thierry Reding3b077af2014-03-14 14:07:50 +010052
53 struct regulator *vdd;
Thierry Reding334ae6b2014-03-14 14:15:10 +010054 bool enabled;
Thierry Reding976cebc2014-08-06 09:14:28 +020055
56 unsigned int video_fifo_depth;
57 unsigned int host_fifo_depth;
Thierry Redinge94236c2014-10-07 16:10:24 +020058
59 /* for ganged-mode support */
60 struct tegra_dsi *master;
61 struct tegra_dsi *slave;
Thierry Redingdec72732013-09-03 08:45:46 +020062};
63
64static inline struct tegra_dsi *
65host1x_client_to_dsi(struct host1x_client *client)
66{
67 return container_of(client, struct tegra_dsi, client);
68}
69
70static inline struct tegra_dsi *host_to_tegra(struct mipi_dsi_host *host)
71{
72 return container_of(host, struct tegra_dsi, host);
73}
74
75static inline struct tegra_dsi *to_dsi(struct tegra_output *output)
76{
77 return container_of(output, struct tegra_dsi, output);
78}
79
Thierry Reding9c0b4ca2014-11-24 12:27:59 +010080static inline u32 tegra_dsi_readl(struct tegra_dsi *dsi, unsigned long reg)
Thierry Redingdec72732013-09-03 08:45:46 +020081{
82 return readl(dsi->regs + (reg << 2));
83}
84
Thierry Reding9c0b4ca2014-11-24 12:27:59 +010085static inline void tegra_dsi_writel(struct tegra_dsi *dsi, u32 value,
Thierry Redingdec72732013-09-03 08:45:46 +020086 unsigned long reg)
87{
88 writel(value, dsi->regs + (reg << 2));
89}
90
91static int tegra_dsi_show_regs(struct seq_file *s, void *data)
92{
93 struct drm_info_node *node = s->private;
94 struct tegra_dsi *dsi = node->info_ent->data;
95
96#define DUMP_REG(name) \
Thierry Reding9c0b4ca2014-11-24 12:27:59 +010097 seq_printf(s, "%-32s %#05x %08x\n", #name, name, \
Thierry Redingdec72732013-09-03 08:45:46 +020098 tegra_dsi_readl(dsi, name))
99
100 DUMP_REG(DSI_INCR_SYNCPT);
101 DUMP_REG(DSI_INCR_SYNCPT_CONTROL);
102 DUMP_REG(DSI_INCR_SYNCPT_ERROR);
103 DUMP_REG(DSI_CTXSW);
104 DUMP_REG(DSI_RD_DATA);
105 DUMP_REG(DSI_WR_DATA);
106 DUMP_REG(DSI_POWER_CONTROL);
107 DUMP_REG(DSI_INT_ENABLE);
108 DUMP_REG(DSI_INT_STATUS);
109 DUMP_REG(DSI_INT_MASK);
110 DUMP_REG(DSI_HOST_CONTROL);
111 DUMP_REG(DSI_CONTROL);
112 DUMP_REG(DSI_SOL_DELAY);
113 DUMP_REG(DSI_MAX_THRESHOLD);
114 DUMP_REG(DSI_TRIGGER);
115 DUMP_REG(DSI_TX_CRC);
116 DUMP_REG(DSI_STATUS);
117
118 DUMP_REG(DSI_INIT_SEQ_CONTROL);
119 DUMP_REG(DSI_INIT_SEQ_DATA_0);
120 DUMP_REG(DSI_INIT_SEQ_DATA_1);
121 DUMP_REG(DSI_INIT_SEQ_DATA_2);
122 DUMP_REG(DSI_INIT_SEQ_DATA_3);
123 DUMP_REG(DSI_INIT_SEQ_DATA_4);
124 DUMP_REG(DSI_INIT_SEQ_DATA_5);
125 DUMP_REG(DSI_INIT_SEQ_DATA_6);
126 DUMP_REG(DSI_INIT_SEQ_DATA_7);
127
128 DUMP_REG(DSI_PKT_SEQ_0_LO);
129 DUMP_REG(DSI_PKT_SEQ_0_HI);
130 DUMP_REG(DSI_PKT_SEQ_1_LO);
131 DUMP_REG(DSI_PKT_SEQ_1_HI);
132 DUMP_REG(DSI_PKT_SEQ_2_LO);
133 DUMP_REG(DSI_PKT_SEQ_2_HI);
134 DUMP_REG(DSI_PKT_SEQ_3_LO);
135 DUMP_REG(DSI_PKT_SEQ_3_HI);
136 DUMP_REG(DSI_PKT_SEQ_4_LO);
137 DUMP_REG(DSI_PKT_SEQ_4_HI);
138 DUMP_REG(DSI_PKT_SEQ_5_LO);
139 DUMP_REG(DSI_PKT_SEQ_5_HI);
140
141 DUMP_REG(DSI_DCS_CMDS);
142
143 DUMP_REG(DSI_PKT_LEN_0_1);
144 DUMP_REG(DSI_PKT_LEN_2_3);
145 DUMP_REG(DSI_PKT_LEN_4_5);
146 DUMP_REG(DSI_PKT_LEN_6_7);
147
148 DUMP_REG(DSI_PHY_TIMING_0);
149 DUMP_REG(DSI_PHY_TIMING_1);
150 DUMP_REG(DSI_PHY_TIMING_2);
151 DUMP_REG(DSI_BTA_TIMING);
152
153 DUMP_REG(DSI_TIMEOUT_0);
154 DUMP_REG(DSI_TIMEOUT_1);
155 DUMP_REG(DSI_TO_TALLY);
156
157 DUMP_REG(DSI_PAD_CONTROL_0);
158 DUMP_REG(DSI_PAD_CONTROL_CD);
159 DUMP_REG(DSI_PAD_CD_STATUS);
160 DUMP_REG(DSI_VIDEO_MODE_CONTROL);
161 DUMP_REG(DSI_PAD_CONTROL_1);
162 DUMP_REG(DSI_PAD_CONTROL_2);
163 DUMP_REG(DSI_PAD_CONTROL_3);
164 DUMP_REG(DSI_PAD_CONTROL_4);
165
166 DUMP_REG(DSI_GANGED_MODE_CONTROL);
167 DUMP_REG(DSI_GANGED_MODE_START);
168 DUMP_REG(DSI_GANGED_MODE_SIZE);
169
170 DUMP_REG(DSI_RAW_DATA_BYTE_COUNT);
171 DUMP_REG(DSI_ULTRA_LOW_POWER_CONTROL);
172
173 DUMP_REG(DSI_INIT_SEQ_DATA_8);
174 DUMP_REG(DSI_INIT_SEQ_DATA_9);
175 DUMP_REG(DSI_INIT_SEQ_DATA_10);
176 DUMP_REG(DSI_INIT_SEQ_DATA_11);
177 DUMP_REG(DSI_INIT_SEQ_DATA_12);
178 DUMP_REG(DSI_INIT_SEQ_DATA_13);
179 DUMP_REG(DSI_INIT_SEQ_DATA_14);
180 DUMP_REG(DSI_INIT_SEQ_DATA_15);
181
182#undef DUMP_REG
183
184 return 0;
185}
186
187static struct drm_info_list debugfs_files[] = {
188 { "regs", tegra_dsi_show_regs, 0, NULL },
189};
190
191static int tegra_dsi_debugfs_init(struct tegra_dsi *dsi,
192 struct drm_minor *minor)
193{
194 const char *name = dev_name(dsi->dev);
195 unsigned int i;
196 int err;
197
198 dsi->debugfs = debugfs_create_dir(name, minor->debugfs_root);
199 if (!dsi->debugfs)
200 return -ENOMEM;
201
202 dsi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
203 GFP_KERNEL);
204 if (!dsi->debugfs_files) {
205 err = -ENOMEM;
206 goto remove;
207 }
208
209 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
210 dsi->debugfs_files[i].data = dsi;
211
212 err = drm_debugfs_create_files(dsi->debugfs_files,
213 ARRAY_SIZE(debugfs_files),
214 dsi->debugfs, minor);
215 if (err < 0)
216 goto free;
217
218 dsi->minor = minor;
219
220 return 0;
221
222free:
223 kfree(dsi->debugfs_files);
224 dsi->debugfs_files = NULL;
225remove:
226 debugfs_remove(dsi->debugfs);
227 dsi->debugfs = NULL;
228
229 return err;
230}
231
232static int tegra_dsi_debugfs_exit(struct tegra_dsi *dsi)
233{
234 drm_debugfs_remove_files(dsi->debugfs_files, ARRAY_SIZE(debugfs_files),
235 dsi->minor);
236 dsi->minor = NULL;
237
238 kfree(dsi->debugfs_files);
239 dsi->debugfs_files = NULL;
240
241 debugfs_remove(dsi->debugfs);
242 dsi->debugfs = NULL;
243
244 return 0;
245}
246
247#define PKT_ID0(id) ((((id) & 0x3f) << 3) | (1 << 9))
248#define PKT_LEN0(len) (((len) & 0x07) << 0)
249#define PKT_ID1(id) ((((id) & 0x3f) << 13) | (1 << 19))
250#define PKT_LEN1(len) (((len) & 0x07) << 10)
251#define PKT_ID2(id) ((((id) & 0x3f) << 23) | (1 << 29))
252#define PKT_LEN2(len) (((len) & 0x07) << 20)
253
254#define PKT_LP (1 << 30)
255#define NUM_PKT_SEQ 12
256
Thierry Reding17297a22014-03-14 14:13:15 +0100257/*
258 * non-burst mode with sync pulses
259 */
260static const u32 pkt_seq_video_non_burst_sync_pulses[NUM_PKT_SEQ] = {
Thierry Redingdec72732013-09-03 08:45:46 +0200261 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
262 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
263 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
264 PKT_LP,
265 [ 1] = 0,
266 [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END) | PKT_LEN0(0) |
267 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
268 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
269 PKT_LP,
270 [ 3] = 0,
271 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
272 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
273 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
274 PKT_LP,
275 [ 5] = 0,
276 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
277 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
278 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
279 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
280 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
281 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
282 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
283 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
284 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
285 PKT_LP,
286 [ 9] = 0,
287 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
288 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
289 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
290 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
291 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
292 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
293};
294
Thierry Reding17297a22014-03-14 14:13:15 +0100295/*
296 * non-burst mode with sync events
297 */
298static const u32 pkt_seq_video_non_burst_sync_events[NUM_PKT_SEQ] = {
299 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
300 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
301 PKT_LP,
302 [ 1] = 0,
303 [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
304 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
305 PKT_LP,
306 [ 3] = 0,
307 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
308 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
309 PKT_LP,
310 [ 5] = 0,
311 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
312 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
313 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
314 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
315 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
316 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
317 PKT_LP,
318 [ 9] = 0,
319 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
320 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
321 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
322 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
323};
324
Thierry Reding337b4432014-11-13 15:02:46 +0100325static const u32 pkt_seq_command_mode[NUM_PKT_SEQ] = {
326 [ 0] = 0,
327 [ 1] = 0,
328 [ 2] = 0,
329 [ 3] = 0,
330 [ 4] = 0,
331 [ 5] = 0,
332 [ 6] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(3) | PKT_LP,
333 [ 7] = 0,
334 [ 8] = 0,
335 [ 9] = 0,
336 [10] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(5) | PKT_LP,
337 [11] = 0,
338};
339
Thierry Redingdec72732013-09-03 08:45:46 +0200340static int tegra_dsi_set_phy_timing(struct tegra_dsi *dsi)
341{
342 struct mipi_dphy_timing timing;
Thierry Reding9c0b4ca2014-11-24 12:27:59 +0100343 unsigned long period;
344 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200345 long rate;
346 int err;
347
348 rate = clk_get_rate(dsi->clk);
349 if (rate < 0)
350 return rate;
351
Thierry Reding369bc652014-11-07 17:17:41 +0100352 period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate * 2);
Thierry Redingdec72732013-09-03 08:45:46 +0200353
354 err = mipi_dphy_timing_get_default(&timing, period);
355 if (err < 0)
356 return err;
357
358 err = mipi_dphy_timing_validate(&timing, period);
359 if (err < 0) {
360 dev_err(dsi->dev, "failed to validate D-PHY timing: %d\n", err);
361 return err;
362 }
363
364 /*
365 * The D-PHY timing fields below are expressed in byte-clock cycles,
366 * so multiply the period by 8.
367 */
368 period *= 8;
369
370 value = DSI_TIMING_FIELD(timing.hsexit, period, 1) << 24 |
371 DSI_TIMING_FIELD(timing.hstrail, period, 0) << 16 |
372 DSI_TIMING_FIELD(timing.hszero, period, 3) << 8 |
373 DSI_TIMING_FIELD(timing.hsprepare, period, 1);
374 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_0);
375
376 value = DSI_TIMING_FIELD(timing.clktrail, period, 1) << 24 |
377 DSI_TIMING_FIELD(timing.clkpost, period, 1) << 16 |
378 DSI_TIMING_FIELD(timing.clkzero, period, 1) << 8 |
379 DSI_TIMING_FIELD(timing.lpx, period, 1);
380 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_1);
381
382 value = DSI_TIMING_FIELD(timing.clkprepare, period, 1) << 16 |
383 DSI_TIMING_FIELD(timing.clkpre, period, 1) << 8 |
384 DSI_TIMING_FIELD(0xff * period, period, 0) << 0;
385 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_2);
386
387 value = DSI_TIMING_FIELD(timing.taget, period, 1) << 16 |
388 DSI_TIMING_FIELD(timing.tasure, period, 1) << 8 |
389 DSI_TIMING_FIELD(timing.tago, period, 1);
390 tegra_dsi_writel(dsi, value, DSI_BTA_TIMING);
391
Sean Paul7e3bc3a2014-10-07 16:04:42 +0200392 if (dsi->slave)
393 return tegra_dsi_set_phy_timing(dsi->slave);
394
Thierry Redingdec72732013-09-03 08:45:46 +0200395 return 0;
396}
397
398static int tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format,
399 unsigned int *mulp, unsigned int *divp)
400{
401 switch (format) {
402 case MIPI_DSI_FMT_RGB666_PACKED:
403 case MIPI_DSI_FMT_RGB888:
404 *mulp = 3;
405 *divp = 1;
406 break;
407
408 case MIPI_DSI_FMT_RGB565:
409 *mulp = 2;
410 *divp = 1;
411 break;
412
413 case MIPI_DSI_FMT_RGB666:
414 *mulp = 9;
415 *divp = 4;
416 break;
417
418 default:
419 return -EINVAL;
420 }
421
422 return 0;
423}
424
Thierry Redingf7d68892014-03-13 08:50:39 +0100425static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format,
426 enum tegra_dsi_format *fmt)
427{
428 switch (format) {
429 case MIPI_DSI_FMT_RGB888:
430 *fmt = TEGRA_DSI_FORMAT_24P;
431 break;
432
433 case MIPI_DSI_FMT_RGB666:
434 *fmt = TEGRA_DSI_FORMAT_18NP;
435 break;
436
437 case MIPI_DSI_FMT_RGB666_PACKED:
438 *fmt = TEGRA_DSI_FORMAT_18P;
439 break;
440
441 case MIPI_DSI_FMT_RGB565:
442 *fmt = TEGRA_DSI_FORMAT_16P;
443 break;
444
445 default:
446 return -EINVAL;
447 }
448
449 return 0;
450}
451
Thierry Redinge94236c2014-10-07 16:10:24 +0200452static void tegra_dsi_ganged_enable(struct tegra_dsi *dsi, unsigned int start,
453 unsigned int size)
454{
455 u32 value;
456
457 tegra_dsi_writel(dsi, start, DSI_GANGED_MODE_START);
458 tegra_dsi_writel(dsi, size << 16 | size, DSI_GANGED_MODE_SIZE);
459
460 value = DSI_GANGED_MODE_CONTROL_ENABLE;
461 tegra_dsi_writel(dsi, value, DSI_GANGED_MODE_CONTROL);
462}
463
Thierry Reding563eff12014-11-13 14:44:27 +0100464static void tegra_dsi_enable(struct tegra_dsi *dsi)
Thierry Redingdec72732013-09-03 08:45:46 +0200465{
Thierry Reding563eff12014-11-13 14:44:27 +0100466 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200467
Thierry Reding563eff12014-11-13 14:44:27 +0100468 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
469 value |= DSI_POWER_CONTROL_ENABLE;
470 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
Thierry Redinge94236c2014-10-07 16:10:24 +0200471
472 if (dsi->slave)
473 tegra_dsi_enable(dsi->slave);
474}
475
476static unsigned int tegra_dsi_get_lanes(struct tegra_dsi *dsi)
477{
478 if (dsi->master)
479 return dsi->master->lanes + dsi->lanes;
480
481 if (dsi->slave)
482 return dsi->lanes + dsi->slave->lanes;
483
484 return dsi->lanes;
Thierry Reding563eff12014-11-13 14:44:27 +0100485}
486
487static int tegra_dsi_configure(struct tegra_dsi *dsi, unsigned int pipe,
488 const struct drm_display_mode *mode)
489{
490 unsigned int hact, hsw, hbp, hfp, i, mul, div;
491 enum tegra_dsi_format format;
492 const u32 *pkt_seq;
493 u32 value;
494 int err;
Thierry Reding334ae6b2014-03-14 14:15:10 +0100495
Thierry Reding17297a22014-03-14 14:13:15 +0100496 if (dsi->flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) {
497 DRM_DEBUG_KMS("Non-burst video mode with sync pulses\n");
498 pkt_seq = pkt_seq_video_non_burst_sync_pulses;
Thierry Reding337b4432014-11-13 15:02:46 +0100499 } else if (dsi->flags & MIPI_DSI_MODE_VIDEO) {
Thierry Reding17297a22014-03-14 14:13:15 +0100500 DRM_DEBUG_KMS("Non-burst video mode with sync events\n");
501 pkt_seq = pkt_seq_video_non_burst_sync_events;
Thierry Reding337b4432014-11-13 15:02:46 +0100502 } else {
503 DRM_DEBUG_KMS("Command mode\n");
504 pkt_seq = pkt_seq_command_mode;
Thierry Reding17297a22014-03-14 14:13:15 +0100505 }
506
Thierry Redingdec72732013-09-03 08:45:46 +0200507 err = tegra_dsi_get_muldiv(dsi->format, &mul, &div);
508 if (err < 0)
509 return err;
510
Thierry Redingf7d68892014-03-13 08:50:39 +0100511 err = tegra_dsi_get_format(dsi->format, &format);
512 if (err < 0)
513 return err;
514
Thierry Redingf7d68892014-03-13 08:50:39 +0100515 value = DSI_CONTROL_CHANNEL(0) | DSI_CONTROL_FORMAT(format) |
Thierry Redingdec72732013-09-03 08:45:46 +0200516 DSI_CONTROL_LANES(dsi->lanes - 1) |
Thierry Reding563eff12014-11-13 14:44:27 +0100517 DSI_CONTROL_SOURCE(pipe);
Thierry Redingdec72732013-09-03 08:45:46 +0200518 tegra_dsi_writel(dsi, value, DSI_CONTROL);
519
Thierry Reding976cebc2014-08-06 09:14:28 +0200520 tegra_dsi_writel(dsi, dsi->video_fifo_depth, DSI_MAX_THRESHOLD);
Thierry Redingdec72732013-09-03 08:45:46 +0200521
Thierry Reding563eff12014-11-13 14:44:27 +0100522 value = DSI_HOST_CONTROL_HS;
Thierry Redingdec72732013-09-03 08:45:46 +0200523 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
524
525 value = tegra_dsi_readl(dsi, DSI_CONTROL);
Thierry Reding563eff12014-11-13 14:44:27 +0100526
Alexandre Courbot0c6b1e42014-07-08 21:32:13 +0900527 if (dsi->flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)
528 value |= DSI_CONTROL_HS_CLK_CTRL;
Thierry Reding563eff12014-11-13 14:44:27 +0100529
Thierry Redingdec72732013-09-03 08:45:46 +0200530 value &= ~DSI_CONTROL_TX_TRIG(3);
Thierry Reding337b4432014-11-13 15:02:46 +0100531
532 /* enable DCS commands for command mode */
533 if (dsi->flags & MIPI_DSI_MODE_VIDEO)
534 value &= ~DSI_CONTROL_DCS_ENABLE;
535 else
536 value |= DSI_CONTROL_DCS_ENABLE;
537
Thierry Redingdec72732013-09-03 08:45:46 +0200538 value |= DSI_CONTROL_VIDEO_ENABLE;
539 value &= ~DSI_CONTROL_HOST_ENABLE;
540 tegra_dsi_writel(dsi, value, DSI_CONTROL);
541
Thierry Redingdec72732013-09-03 08:45:46 +0200542 for (i = 0; i < NUM_PKT_SEQ; i++)
543 tegra_dsi_writel(dsi, pkt_seq[i], DSI_PKT_SEQ_0_LO + i);
544
Thierry Reding337b4432014-11-13 15:02:46 +0100545 if (dsi->flags & MIPI_DSI_MODE_VIDEO) {
546 /* horizontal active pixels */
547 hact = mode->hdisplay * mul / div;
Thierry Redingdec72732013-09-03 08:45:46 +0200548
Thierry Reding337b4432014-11-13 15:02:46 +0100549 /* horizontal sync width */
550 hsw = (mode->hsync_end - mode->hsync_start) * mul / div;
551 hsw -= 10;
Thierry Redingdec72732013-09-03 08:45:46 +0200552
Thierry Reding337b4432014-11-13 15:02:46 +0100553 /* horizontal back porch */
554 hbp = (mode->htotal - mode->hsync_end) * mul / div;
555 hbp -= 14;
Thierry Redingdec72732013-09-03 08:45:46 +0200556
Thierry Reding337b4432014-11-13 15:02:46 +0100557 /* horizontal front porch */
558 hfp = (mode->hsync_start - mode->hdisplay) * mul / div;
559 hfp -= 8;
Thierry Redingdec72732013-09-03 08:45:46 +0200560
Thierry Reding337b4432014-11-13 15:02:46 +0100561 tegra_dsi_writel(dsi, hsw << 16 | 0, DSI_PKT_LEN_0_1);
562 tegra_dsi_writel(dsi, hact << 16 | hbp, DSI_PKT_LEN_2_3);
563 tegra_dsi_writel(dsi, hfp, DSI_PKT_LEN_4_5);
564 tegra_dsi_writel(dsi, 0x0f0f << 16, DSI_PKT_LEN_6_7);
Thierry Redingdec72732013-09-03 08:45:46 +0200565
Thierry Reding337b4432014-11-13 15:02:46 +0100566 /* set SOL delay (for non-burst mode only) */
567 tegra_dsi_writel(dsi, 8 * mul / div, DSI_SOL_DELAY);
Thierry Redinge94236c2014-10-07 16:10:24 +0200568
569 /* TODO: implement ganged mode */
Thierry Reding337b4432014-11-13 15:02:46 +0100570 } else {
571 u16 bytes;
572
Thierry Redinge94236c2014-10-07 16:10:24 +0200573 if (dsi->master || dsi->slave) {
574 /*
575 * For ganged mode, assume symmetric left-right mode.
576 */
577 bytes = 1 + (mode->hdisplay / 2) * mul / div;
578 } else {
579 /* 1 byte (DCS command) + pixel data */
580 bytes = 1 + mode->hdisplay * mul / div;
581 }
Thierry Reding337b4432014-11-13 15:02:46 +0100582
583 tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_0_1);
584 tegra_dsi_writel(dsi, bytes << 16, DSI_PKT_LEN_2_3);
585 tegra_dsi_writel(dsi, bytes << 16, DSI_PKT_LEN_4_5);
586 tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_6_7);
587
588 value = MIPI_DCS_WRITE_MEMORY_START << 8 |
589 MIPI_DCS_WRITE_MEMORY_CONTINUE;
590 tegra_dsi_writel(dsi, value, DSI_DCS_CMDS);
591
Thierry Redinge94236c2014-10-07 16:10:24 +0200592 /* set SOL delay */
593 if (dsi->master || dsi->slave) {
594 unsigned int lanes = tegra_dsi_get_lanes(dsi);
595 unsigned long delay, bclk, bclk_ganged;
596
597 /* SOL to valid, valid to FIFO and FIFO write delay */
598 delay = 4 + 4 + 2;
599 delay = DIV_ROUND_UP(delay * mul, div * lanes);
600 /* FIFO read delay */
601 delay = delay + 6;
602
603 bclk = DIV_ROUND_UP(mode->htotal * mul, div * lanes);
604 bclk_ganged = DIV_ROUND_UP(bclk * lanes / 2, lanes);
605 value = bclk - bclk_ganged + delay + 20;
606 } else {
607 /* TODO: revisit for non-ganged mode */
608 value = 8 * mul / div;
609 }
Thierry Reding337b4432014-11-13 15:02:46 +0100610
611 tegra_dsi_writel(dsi, value, DSI_SOL_DELAY);
612 }
Thierry Redingdec72732013-09-03 08:45:46 +0200613
Thierry Redinge94236c2014-10-07 16:10:24 +0200614 if (dsi->slave) {
615 err = tegra_dsi_configure(dsi->slave, pipe, mode);
616 if (err < 0)
617 return err;
618
619 /*
620 * TODO: Support modes other than symmetrical left-right
621 * split.
622 */
623 tegra_dsi_ganged_enable(dsi, 0, mode->hdisplay / 2);
624 tegra_dsi_ganged_enable(dsi->slave, mode->hdisplay / 2,
625 mode->hdisplay / 2);
626 }
627
Thierry Reding563eff12014-11-13 14:44:27 +0100628 return 0;
629}
630
631static int tegra_output_dsi_enable(struct tegra_output *output)
632{
633 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
634 const struct drm_display_mode *mode = &dc->base.mode;
635 struct tegra_dsi *dsi = to_dsi(output);
636 u32 value;
637 int err;
638
639 if (dsi->enabled)
640 return 0;
641
642 err = tegra_dsi_configure(dsi, dc->pipe, mode);
643 if (err < 0)
644 return err;
645
Thierry Redingdec72732013-09-03 08:45:46 +0200646 /* enable display controller */
647 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
648 value |= DSI_ENABLE;
649 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
650
Thierry Redingdec72732013-09-03 08:45:46 +0200651 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
652 value &= ~DISP_CTRL_MODE_MASK;
653 value |= DISP_CTRL_MODE_C_DISPLAY;
654 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
655
Thierry Reding72d30282013-12-12 11:06:55 +0100656 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
657 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
658 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
659 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
660
Thierry Reding62b9e062014-11-21 17:33:33 +0100661 tegra_dc_commit(dc);
Thierry Redingdec72732013-09-03 08:45:46 +0200662
663 /* enable DSI controller */
Thierry Reding563eff12014-11-13 14:44:27 +0100664 tegra_dsi_enable(dsi);
Thierry Redingdec72732013-09-03 08:45:46 +0200665
Thierry Reding334ae6b2014-03-14 14:15:10 +0100666 dsi->enabled = true;
667
Thierry Redingdec72732013-09-03 08:45:46 +0200668 return 0;
669}
670
Thierry Reding563eff12014-11-13 14:44:27 +0100671static int tegra_dsi_wait_idle(struct tegra_dsi *dsi, unsigned long timeout)
672{
673 u32 value;
674
675 timeout = jiffies + msecs_to_jiffies(timeout);
676
677 while (time_before(jiffies, timeout)) {
678 value = tegra_dsi_readl(dsi, DSI_STATUS);
679 if (value & DSI_STATUS_IDLE)
680 return 0;
681
682 usleep_range(1000, 2000);
683 }
684
685 return -ETIMEDOUT;
686}
687
688static void tegra_dsi_video_disable(struct tegra_dsi *dsi)
689{
690 u32 value;
691
692 value = tegra_dsi_readl(dsi, DSI_CONTROL);
693 value &= ~DSI_CONTROL_VIDEO_ENABLE;
694 tegra_dsi_writel(dsi, value, DSI_CONTROL);
Thierry Redinge94236c2014-10-07 16:10:24 +0200695
696 if (dsi->slave)
697 tegra_dsi_video_disable(dsi->slave);
698}
699
700static void tegra_dsi_ganged_disable(struct tegra_dsi *dsi)
701{
702 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_START);
703 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_SIZE);
704 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_CONTROL);
Thierry Reding563eff12014-11-13 14:44:27 +0100705}
706
707static void tegra_dsi_disable(struct tegra_dsi *dsi)
708{
709 u32 value;
710
Thierry Redinge94236c2014-10-07 16:10:24 +0200711 if (dsi->slave) {
712 tegra_dsi_ganged_disable(dsi->slave);
713 tegra_dsi_ganged_disable(dsi);
714 }
715
Thierry Reding563eff12014-11-13 14:44:27 +0100716 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
717 value &= ~DSI_POWER_CONTROL_ENABLE;
718 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
719
Thierry Redinge94236c2014-10-07 16:10:24 +0200720 if (dsi->slave)
721 tegra_dsi_disable(dsi->slave);
722
Thierry Reding563eff12014-11-13 14:44:27 +0100723 usleep_range(5000, 10000);
724}
725
Thierry Reding92f0e072014-11-24 16:29:40 +0100726static void tegra_dsi_soft_reset(struct tegra_dsi *dsi)
727{
728 u32 value;
729
730 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
731 value &= ~DSI_POWER_CONTROL_ENABLE;
732 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
733
734 usleep_range(300, 1000);
735
736 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
737 value |= DSI_POWER_CONTROL_ENABLE;
738 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
739
740 usleep_range(300, 1000);
741
742 value = tegra_dsi_readl(dsi, DSI_TRIGGER);
743 if (value)
744 tegra_dsi_writel(dsi, 0, DSI_TRIGGER);
745
746 if (dsi->slave)
747 tegra_dsi_soft_reset(dsi->slave);
748}
749
Thierry Redingdec72732013-09-03 08:45:46 +0200750static int tegra_output_dsi_disable(struct tegra_output *output)
751{
752 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
753 struct tegra_dsi *dsi = to_dsi(output);
Thierry Reding9c0b4ca2014-11-24 12:27:59 +0100754 u32 value;
Thierry Reding563eff12014-11-13 14:44:27 +0100755 int err;
Thierry Redingdec72732013-09-03 08:45:46 +0200756
Thierry Reding334ae6b2014-03-14 14:15:10 +0100757 if (!dsi->enabled)
758 return 0;
759
Thierry Reding563eff12014-11-13 14:44:27 +0100760 tegra_dsi_video_disable(dsi);
Thierry Redingdec72732013-09-03 08:45:46 +0200761
762 /*
Thierry Reding72d30282013-12-12 11:06:55 +0100763 * The following accesses registers of the display controller, so make
764 * sure it's only executed when the output is attached to one.
Thierry Redingdec72732013-09-03 08:45:46 +0200765 */
766 if (dc) {
Thierry Reding72d30282013-12-12 11:06:55 +0100767 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
768 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
769 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
770 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
771
Thierry Redingdec72732013-09-03 08:45:46 +0200772 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
773 value &= ~DISP_CTRL_MODE_MASK;
774 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
775
776 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
777 value &= ~DSI_ENABLE;
778 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Reding72d30282013-12-12 11:06:55 +0100779
Thierry Reding62b9e062014-11-21 17:33:33 +0100780 tegra_dc_commit(dc);
Thierry Redingdec72732013-09-03 08:45:46 +0200781 }
782
Thierry Reding563eff12014-11-13 14:44:27 +0100783 err = tegra_dsi_wait_idle(dsi, 100);
784 if (err < 0)
785 dev_dbg(dsi->dev, "failed to idle DSI: %d\n", err);
786
Thierry Reding92f0e072014-11-24 16:29:40 +0100787 tegra_dsi_soft_reset(dsi);
Thierry Reding563eff12014-11-13 14:44:27 +0100788 tegra_dsi_disable(dsi);
789
Thierry Reding334ae6b2014-03-14 14:15:10 +0100790 dsi->enabled = false;
791
Thierry Redingdec72732013-09-03 08:45:46 +0200792 return 0;
793}
794
Thierry Reding3f6b4062014-11-13 14:50:33 +0100795static void tegra_dsi_set_timeout(struct tegra_dsi *dsi, unsigned long bclk,
796 unsigned int vrefresh)
797{
798 unsigned int timeout;
799 u32 value;
800
801 /* one frame high-speed transmission timeout */
802 timeout = (bclk / vrefresh) / 512;
803 value = DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout);
804 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_0);
805
806 /* 2 ms peripheral timeout for panel */
807 timeout = 2 * bclk / 512 * 1000;
808 value = DSI_TIMEOUT_PR(timeout) | DSI_TIMEOUT_TA(0x2000);
809 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_1);
810
811 value = DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
812 tegra_dsi_writel(dsi, value, DSI_TO_TALLY);
Thierry Redinge94236c2014-10-07 16:10:24 +0200813
814 if (dsi->slave)
815 tegra_dsi_set_timeout(dsi->slave, bclk, vrefresh);
Thierry Reding3f6b4062014-11-13 14:50:33 +0100816}
817
Thierry Redingdec72732013-09-03 08:45:46 +0200818static int tegra_output_dsi_setup_clock(struct tegra_output *output,
Thierry Reding91eded92014-03-26 13:32:21 +0100819 struct clk *clk, unsigned long pclk,
820 unsigned int *divp)
Thierry Redingdec72732013-09-03 08:45:46 +0200821{
822 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
823 struct drm_display_mode *mode = &dc->base.mode;
Thierry Redingdec72732013-09-03 08:45:46 +0200824 struct tegra_dsi *dsi = to_dsi(output);
Thierry Redinge94236c2014-10-07 16:10:24 +0200825 unsigned int mul, div, vrefresh, lanes;
Thierry Reding3f6b4062014-11-13 14:50:33 +0100826 unsigned long bclk, plld;
Thierry Redingdec72732013-09-03 08:45:46 +0200827 int err;
828
Thierry Redinge94236c2014-10-07 16:10:24 +0200829 lanes = tegra_dsi_get_lanes(dsi);
830
Thierry Redingdec72732013-09-03 08:45:46 +0200831 err = tegra_dsi_get_muldiv(dsi->format, &mul, &div);
832 if (err < 0)
833 return err;
834
Thierry Redinge94236c2014-10-07 16:10:24 +0200835 DRM_DEBUG_KMS("mul: %u, div: %u, lanes: %u\n", mul, div, lanes);
Thierry Redingdec72732013-09-03 08:45:46 +0200836 vrefresh = drm_mode_vrefresh(mode);
Thierry Reding91eded92014-03-26 13:32:21 +0100837 DRM_DEBUG_KMS("vrefresh: %u\n", vrefresh);
Thierry Redingdec72732013-09-03 08:45:46 +0200838
Thierry Reding91eded92014-03-26 13:32:21 +0100839 /* compute byte clock */
Thierry Redinge94236c2014-10-07 16:10:24 +0200840 bclk = (pclk * mul) / (div * lanes);
Thierry Reding91eded92014-03-26 13:32:21 +0100841
842 /*
843 * Compute bit clock and round up to the next MHz.
844 */
Thierry Reding030611e2014-11-13 14:32:06 +0100845 plld = DIV_ROUND_UP(bclk * 8, USEC_PER_SEC) * USEC_PER_SEC;
Thierry Reding91eded92014-03-26 13:32:21 +0100846
847 /*
848 * We divide the frequency by two here, but we make up for that by
849 * setting the shift clock divider (further below) to half of the
850 * correct value.
851 */
852 plld /= 2;
Thierry Redingdec72732013-09-03 08:45:46 +0200853
854 err = clk_set_parent(clk, dsi->clk_parent);
855 if (err < 0) {
856 dev_err(dsi->dev, "failed to set parent clock: %d\n", err);
857 return err;
858 }
859
Thierry Reding91eded92014-03-26 13:32:21 +0100860 err = clk_set_rate(dsi->clk_parent, plld);
Thierry Redingdec72732013-09-03 08:45:46 +0200861 if (err < 0) {
862 dev_err(dsi->dev, "failed to set base clock rate to %lu Hz\n",
Thierry Reding91eded92014-03-26 13:32:21 +0100863 plld);
Thierry Redingdec72732013-09-03 08:45:46 +0200864 return err;
865 }
866
867 /*
Thierry Reding91eded92014-03-26 13:32:21 +0100868 * Derive pixel clock from bit clock using the shift clock divider.
869 * Note that this is only half of what we would expect, but we need
870 * that to make up for the fact that we divided the bit clock by a
871 * factor of two above.
872 *
873 * It's not clear exactly why this is necessary, but the display is
874 * not working properly otherwise. Perhaps the PLLs cannot generate
875 * frequencies sufficiently high.
876 */
Thierry Redinge94236c2014-10-07 16:10:24 +0200877 *divp = ((8 * mul) / (div * lanes)) - 2;
Thierry Reding91eded92014-03-26 13:32:21 +0100878
879 /*
Thierry Redingdec72732013-09-03 08:45:46 +0200880 * XXX: Move the below somewhere else so that we don't need to have
881 * access to the vrefresh in this function?
882 */
Thierry Reding3f6b4062014-11-13 14:50:33 +0100883 tegra_dsi_set_timeout(dsi, bclk, vrefresh);
Thierry Redingdec72732013-09-03 08:45:46 +0200884
Sean Paul7e3bc3a2014-10-07 16:04:42 +0200885 err = tegra_dsi_set_phy_timing(dsi);
886 if (err < 0)
887 return err;
888
Thierry Redingdec72732013-09-03 08:45:46 +0200889 return 0;
890}
891
892static int tegra_output_dsi_check_mode(struct tegra_output *output,
893 struct drm_display_mode *mode,
894 enum drm_mode_status *status)
895{
896 /*
897 * FIXME: For now, always assume that the mode is okay.
898 */
899
900 *status = MODE_OK;
901
902 return 0;
903}
904
905static const struct tegra_output_ops dsi_ops = {
906 .enable = tegra_output_dsi_enable,
907 .disable = tegra_output_dsi_disable,
908 .setup_clock = tegra_output_dsi_setup_clock,
909 .check_mode = tegra_output_dsi_check_mode,
910};
911
912static int tegra_dsi_pad_enable(struct tegra_dsi *dsi)
913{
Thierry Reding9c0b4ca2014-11-24 12:27:59 +0100914 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200915
916 value = DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
917 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_0);
918
919 return 0;
920}
921
922static int tegra_dsi_pad_calibrate(struct tegra_dsi *dsi)
923{
Thierry Reding183ef282014-11-13 14:27:29 +0100924 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200925
926 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_0);
927 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_1);
928 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_2);
929 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_3);
930 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_4);
931
932 /* start calibration */
933 tegra_dsi_pad_enable(dsi);
934
935 value = DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
936 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
937 DSI_PAD_OUT_CLK(0x0);
938 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_2);
939
940 return tegra_mipi_calibrate(dsi->mipi);
941}
942
943static int tegra_dsi_init(struct host1x_client *client)
944{
Thierry Reding9910f5c2014-05-22 09:57:15 +0200945 struct drm_device *drm = dev_get_drvdata(client->parent);
Thierry Redingdec72732013-09-03 08:45:46 +0200946 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
Thierry Redingdec72732013-09-03 08:45:46 +0200947 int err;
948
Thierry Reding201106d2014-11-24 16:31:48 +0100949 reset_control_deassert(dsi->rst);
950
951 err = tegra_dsi_pad_calibrate(dsi);
952 if (err < 0) {
953 dev_err(dsi->dev, "MIPI calibration failed: %d\n", err);
954 goto reset;
955 }
956
Thierry Redinge94236c2014-10-07 16:10:24 +0200957 /* Gangsters must not register their own outputs. */
958 if (!dsi->master) {
959 dsi->output.type = TEGRA_OUTPUT_DSI;
960 dsi->output.dev = client->dev;
961 dsi->output.ops = &dsi_ops;
Thierry Redingdec72732013-09-03 08:45:46 +0200962
Thierry Redinge94236c2014-10-07 16:10:24 +0200963 err = tegra_output_init(drm, &dsi->output);
964 if (err < 0) {
965 dev_err(client->dev, "output setup failed: %d\n", err);
966 return err;
967 }
Thierry Redingdec72732013-09-03 08:45:46 +0200968 }
969
970 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding9910f5c2014-05-22 09:57:15 +0200971 err = tegra_dsi_debugfs_init(dsi, drm->primary);
Thierry Redingdec72732013-09-03 08:45:46 +0200972 if (err < 0)
973 dev_err(dsi->dev, "debugfs setup failed: %d\n", err);
974 }
975
Thierry Redingdec72732013-09-03 08:45:46 +0200976 return 0;
Thierry Reding201106d2014-11-24 16:31:48 +0100977
978reset:
979 reset_control_assert(dsi->rst);
980 return err;
Thierry Redingdec72732013-09-03 08:45:46 +0200981}
982
983static int tegra_dsi_exit(struct host1x_client *client)
984{
985 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
986 int err;
987
988 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
989 err = tegra_dsi_debugfs_exit(dsi);
990 if (err < 0)
991 dev_err(dsi->dev, "debugfs cleanup failed: %d\n", err);
992 }
993
Thierry Redinge94236c2014-10-07 16:10:24 +0200994 if (!dsi->master) {
995 err = tegra_output_disable(&dsi->output);
996 if (err < 0) {
997 dev_err(client->dev, "output failed to disable: %d\n",
998 err);
999 return err;
1000 }
Thierry Redingdec72732013-09-03 08:45:46 +02001001
Thierry Redinge94236c2014-10-07 16:10:24 +02001002 err = tegra_output_exit(&dsi->output);
1003 if (err < 0) {
1004 dev_err(client->dev, "output cleanup failed: %d\n",
1005 err);
1006 return err;
1007 }
Thierry Redingdec72732013-09-03 08:45:46 +02001008 }
1009
Thierry Reding201106d2014-11-24 16:31:48 +01001010 reset_control_assert(dsi->rst);
1011
Thierry Redingdec72732013-09-03 08:45:46 +02001012 return 0;
1013}
1014
1015static const struct host1x_client_ops dsi_client_ops = {
1016 .init = tegra_dsi_init,
1017 .exit = tegra_dsi_exit,
1018};
1019
1020static int tegra_dsi_setup_clocks(struct tegra_dsi *dsi)
1021{
1022 struct clk *parent;
1023 int err;
1024
1025 parent = clk_get_parent(dsi->clk);
1026 if (!parent)
1027 return -EINVAL;
1028
1029 err = clk_set_parent(parent, dsi->clk_parent);
1030 if (err < 0)
1031 return err;
1032
1033 return 0;
1034}
1035
Thierry Reding0fffdf62014-11-07 17:25:26 +01001036static const char * const error_report[16] = {
1037 "SoT Error",
1038 "SoT Sync Error",
1039 "EoT Sync Error",
1040 "Escape Mode Entry Command Error",
1041 "Low-Power Transmit Sync Error",
1042 "Peripheral Timeout Error",
1043 "False Control Error",
1044 "Contention Detected",
1045 "ECC Error, single-bit",
1046 "ECC Error, multi-bit",
1047 "Checksum Error",
1048 "DSI Data Type Not Recognized",
1049 "DSI VC ID Invalid",
1050 "Invalid Transmission Length",
1051 "Reserved",
1052 "DSI Protocol Violation",
1053};
1054
1055static ssize_t tegra_dsi_read_response(struct tegra_dsi *dsi,
1056 const struct mipi_dsi_msg *msg,
1057 size_t count)
1058{
1059 u8 *rx = msg->rx_buf;
1060 unsigned int i, j, k;
1061 size_t size = 0;
1062 u16 errors;
1063 u32 value;
1064
1065 /* read and parse packet header */
1066 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1067
1068 switch (value & 0x3f) {
1069 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
1070 errors = (value >> 8) & 0xffff;
1071 dev_dbg(dsi->dev, "Acknowledge and error report: %04x\n",
1072 errors);
1073 for (i = 0; i < ARRAY_SIZE(error_report); i++)
1074 if (errors & BIT(i))
1075 dev_dbg(dsi->dev, " %2u: %s\n", i,
1076 error_report[i]);
1077 break;
1078
1079 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
1080 rx[0] = (value >> 8) & 0xff;
1081 size = 1;
1082 break;
1083
1084 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
1085 rx[0] = (value >> 8) & 0xff;
1086 rx[1] = (value >> 16) & 0xff;
1087 size = 2;
1088 break;
1089
1090 case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
1091 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
1092 break;
1093
1094 case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
1095 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
1096 break;
1097
1098 default:
1099 dev_err(dsi->dev, "unhandled response type: %02x\n",
1100 value & 0x3f);
1101 return -EPROTO;
1102 }
1103
1104 size = min(size, msg->rx_len);
1105
1106 if (msg->rx_buf && size > 0) {
1107 for (i = 0, j = 0; i < count - 1; i++, j += 4) {
1108 u8 *rx = msg->rx_buf + j;
1109
1110 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1111
1112 for (k = 0; k < 4 && (j + k) < msg->rx_len; k++)
1113 rx[j + k] = (value >> (k << 3)) & 0xff;
1114 }
1115 }
1116
1117 return size;
1118}
1119
1120static int tegra_dsi_transmit(struct tegra_dsi *dsi, unsigned long timeout)
1121{
1122 tegra_dsi_writel(dsi, DSI_TRIGGER_HOST, DSI_TRIGGER);
1123
1124 timeout = jiffies + msecs_to_jiffies(timeout);
1125
1126 while (time_before(jiffies, timeout)) {
1127 u32 value = tegra_dsi_readl(dsi, DSI_TRIGGER);
1128 if ((value & DSI_TRIGGER_HOST) == 0)
1129 return 0;
1130
1131 usleep_range(1000, 2000);
1132 }
1133
1134 DRM_DEBUG_KMS("timeout waiting for transmission to complete\n");
1135 return -ETIMEDOUT;
1136}
1137
1138static int tegra_dsi_wait_for_response(struct tegra_dsi *dsi,
1139 unsigned long timeout)
1140{
1141 timeout = jiffies + msecs_to_jiffies(250);
1142
1143 while (time_before(jiffies, timeout)) {
1144 u32 value = tegra_dsi_readl(dsi, DSI_STATUS);
1145 u8 count = value & 0x1f;
1146
1147 if (count > 0)
1148 return count;
1149
1150 usleep_range(1000, 2000);
1151 }
1152
1153 DRM_DEBUG_KMS("peripheral returned no data\n");
1154 return -ETIMEDOUT;
1155}
1156
1157static void tegra_dsi_writesl(struct tegra_dsi *dsi, unsigned long offset,
1158 const void *buffer, size_t size)
1159{
1160 const u8 *buf = buffer;
1161 size_t i, j;
1162 u32 value;
1163
1164 for (j = 0; j < size; j += 4) {
1165 value = 0;
1166
1167 for (i = 0; i < 4 && j + i < size; i++)
1168 value |= buf[j + i] << (i << 3);
1169
1170 tegra_dsi_writel(dsi, value, DSI_WR_DATA);
1171 }
1172}
1173
1174static ssize_t tegra_dsi_host_transfer(struct mipi_dsi_host *host,
1175 const struct mipi_dsi_msg *msg)
1176{
1177 struct tegra_dsi *dsi = host_to_tegra(host);
1178 struct mipi_dsi_packet packet;
1179 const u8 *header;
1180 size_t count;
1181 ssize_t err;
1182 u32 value;
1183
1184 err = mipi_dsi_create_packet(&packet, msg);
1185 if (err < 0)
1186 return err;
1187
1188 header = packet.header;
1189
1190 /* maximum FIFO depth is 1920 words */
1191 if (packet.size > dsi->video_fifo_depth * 4)
1192 return -ENOSPC;
1193
1194 /* reset underflow/overflow flags */
1195 value = tegra_dsi_readl(dsi, DSI_STATUS);
1196 if (value & (DSI_STATUS_UNDERFLOW | DSI_STATUS_OVERFLOW)) {
1197 value = DSI_HOST_CONTROL_FIFO_RESET;
1198 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1199 usleep_range(10, 20);
1200 }
1201
1202 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
1203 value |= DSI_POWER_CONTROL_ENABLE;
1204 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
1205
1206 usleep_range(5000, 10000);
1207
1208 value = DSI_HOST_CONTROL_CRC_RESET | DSI_HOST_CONTROL_TX_TRIG_HOST |
1209 DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC;
1210
1211 if ((msg->flags & MIPI_DSI_MSG_USE_LPM) == 0)
1212 value |= DSI_HOST_CONTROL_HS;
1213
1214 /*
1215 * The host FIFO has a maximum of 64 words, so larger transmissions
1216 * need to use the video FIFO.
1217 */
1218 if (packet.size > dsi->host_fifo_depth * 4)
1219 value |= DSI_HOST_CONTROL_FIFO_SEL;
1220
1221 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1222
1223 /*
1224 * For reads and messages with explicitly requested ACK, generate a
1225 * BTA sequence after the transmission of the packet.
1226 */
1227 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
1228 (msg->rx_buf && msg->rx_len > 0)) {
1229 value = tegra_dsi_readl(dsi, DSI_HOST_CONTROL);
1230 value |= DSI_HOST_CONTROL_PKT_BTA;
1231 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1232 }
1233
1234 value = DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE;
1235 tegra_dsi_writel(dsi, value, DSI_CONTROL);
1236
1237 /* write packet header, ECC is generated by hardware */
1238 value = header[2] << 16 | header[1] << 8 | header[0];
1239 tegra_dsi_writel(dsi, value, DSI_WR_DATA);
1240
1241 /* write payload (if any) */
1242 if (packet.payload_length > 0)
1243 tegra_dsi_writesl(dsi, DSI_WR_DATA, packet.payload,
1244 packet.payload_length);
1245
1246 err = tegra_dsi_transmit(dsi, 250);
1247 if (err < 0)
1248 return err;
1249
1250 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
1251 (msg->rx_buf && msg->rx_len > 0)) {
1252 err = tegra_dsi_wait_for_response(dsi, 250);
1253 if (err < 0)
1254 return err;
1255
1256 count = err;
1257
1258 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1259 switch (value) {
1260 case 0x84:
1261 /*
1262 dev_dbg(dsi->dev, "ACK\n");
1263 */
1264 break;
1265
1266 case 0x87:
1267 /*
1268 dev_dbg(dsi->dev, "ESCAPE\n");
1269 */
1270 break;
1271
1272 default:
1273 dev_err(dsi->dev, "unknown status: %08x\n", value);
1274 break;
1275 }
1276
1277 if (count > 1) {
1278 err = tegra_dsi_read_response(dsi, msg, count);
1279 if (err < 0)
1280 dev_err(dsi->dev,
1281 "failed to parse response: %zd\n",
1282 err);
1283 else {
1284 /*
1285 * For read commands, return the number of
1286 * bytes returned by the peripheral.
1287 */
1288 count = err;
1289 }
1290 }
1291 } else {
1292 /*
1293 * For write commands, we have transmitted the 4-byte header
1294 * plus the variable-length payload.
1295 */
1296 count = 4 + packet.payload_length;
1297 }
1298
1299 return count;
1300}
1301
Thierry Redinge94236c2014-10-07 16:10:24 +02001302static int tegra_dsi_ganged_setup(struct tegra_dsi *dsi)
1303{
1304 struct clk *parent;
1305 int err;
1306
1307 /* make sure both DSI controllers share the same PLL */
1308 parent = clk_get_parent(dsi->slave->clk);
1309 if (!parent)
1310 return -EINVAL;
1311
1312 err = clk_set_parent(parent, dsi->clk_parent);
1313 if (err < 0)
1314 return err;
1315
1316 return 0;
1317}
1318
Thierry Redingdec72732013-09-03 08:45:46 +02001319static int tegra_dsi_host_attach(struct mipi_dsi_host *host,
1320 struct mipi_dsi_device *device)
1321{
1322 struct tegra_dsi *dsi = host_to_tegra(host);
Thierry Redingdec72732013-09-03 08:45:46 +02001323
Thierry Reding17297a22014-03-14 14:13:15 +01001324 dsi->flags = device->mode_flags;
Thierry Redingdec72732013-09-03 08:45:46 +02001325 dsi->format = device->format;
1326 dsi->lanes = device->lanes;
1327
Thierry Redinge94236c2014-10-07 16:10:24 +02001328 if (dsi->slave) {
1329 int err;
1330
1331 dev_dbg(dsi->dev, "attaching dual-channel device %s\n",
1332 dev_name(&device->dev));
1333
1334 err = tegra_dsi_ganged_setup(dsi);
1335 if (err < 0) {
1336 dev_err(dsi->dev, "failed to set up ganged mode: %d\n",
1337 err);
1338 return err;
1339 }
1340 }
1341
1342 /*
1343 * Slaves don't have a panel associated with them, so they provide
1344 * merely the second channel.
1345 */
1346 if (!dsi->master) {
1347 struct tegra_output *output = &dsi->output;
1348
1349 output->panel = of_drm_find_panel(device->dev.of_node);
1350 if (output->panel && output->connector.dev) {
1351 drm_panel_attach(output->panel, &output->connector);
Thierry Redingdec72732013-09-03 08:45:46 +02001352 drm_helper_hpd_irq_event(output->connector.dev);
Thierry Redinge94236c2014-10-07 16:10:24 +02001353 }
Thierry Redingdec72732013-09-03 08:45:46 +02001354 }
1355
1356 return 0;
1357}
1358
1359static int tegra_dsi_host_detach(struct mipi_dsi_host *host,
1360 struct mipi_dsi_device *device)
1361{
1362 struct tegra_dsi *dsi = host_to_tegra(host);
1363 struct tegra_output *output = &dsi->output;
1364
1365 if (output->panel && &device->dev == output->panel->dev) {
Thierry Redingba3df972014-11-13 14:54:01 +01001366 output->panel = NULL;
1367
Thierry Redingdec72732013-09-03 08:45:46 +02001368 if (output->connector.dev)
1369 drm_helper_hpd_irq_event(output->connector.dev);
Thierry Redingdec72732013-09-03 08:45:46 +02001370 }
1371
1372 return 0;
1373}
1374
1375static const struct mipi_dsi_host_ops tegra_dsi_host_ops = {
1376 .attach = tegra_dsi_host_attach,
1377 .detach = tegra_dsi_host_detach,
Thierry Reding0fffdf62014-11-07 17:25:26 +01001378 .transfer = tegra_dsi_host_transfer,
Thierry Redingdec72732013-09-03 08:45:46 +02001379};
1380
Thierry Redinge94236c2014-10-07 16:10:24 +02001381static int tegra_dsi_ganged_probe(struct tegra_dsi *dsi)
1382{
1383 struct device_node *np;
1384
1385 np = of_parse_phandle(dsi->dev->of_node, "nvidia,ganged-mode", 0);
1386 if (np) {
1387 struct platform_device *gangster = of_find_device_by_node(np);
1388
1389 dsi->slave = platform_get_drvdata(gangster);
1390 of_node_put(np);
1391
1392 if (!dsi->slave)
1393 return -EPROBE_DEFER;
1394
1395 dsi->slave->master = dsi;
1396 }
1397
1398 return 0;
1399}
1400
Thierry Redingdec72732013-09-03 08:45:46 +02001401static int tegra_dsi_probe(struct platform_device *pdev)
1402{
1403 struct tegra_dsi *dsi;
1404 struct resource *regs;
1405 int err;
1406
1407 dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL);
1408 if (!dsi)
1409 return -ENOMEM;
1410
1411 dsi->output.dev = dsi->dev = &pdev->dev;
Thierry Reding976cebc2014-08-06 09:14:28 +02001412 dsi->video_fifo_depth = 1920;
1413 dsi->host_fifo_depth = 64;
Thierry Redingdec72732013-09-03 08:45:46 +02001414
Thierry Redinge94236c2014-10-07 16:10:24 +02001415 err = tegra_dsi_ganged_probe(dsi);
1416 if (err < 0)
1417 return err;
1418
Thierry Redingdec72732013-09-03 08:45:46 +02001419 err = tegra_output_probe(&dsi->output);
1420 if (err < 0)
1421 return err;
1422
Thierry Redingba3df972014-11-13 14:54:01 +01001423 dsi->output.connector.polled = DRM_CONNECTOR_POLL_HPD;
1424
Thierry Redingdec72732013-09-03 08:45:46 +02001425 /*
1426 * Assume these values by default. When a DSI peripheral driver
1427 * attaches to the DSI host, the parameters will be taken from
1428 * the attached device.
1429 */
Thierry Reding17297a22014-03-14 14:13:15 +01001430 dsi->flags = MIPI_DSI_MODE_VIDEO;
Thierry Redingdec72732013-09-03 08:45:46 +02001431 dsi->format = MIPI_DSI_FMT_RGB888;
1432 dsi->lanes = 4;
1433
1434 dsi->rst = devm_reset_control_get(&pdev->dev, "dsi");
1435 if (IS_ERR(dsi->rst))
1436 return PTR_ERR(dsi->rst);
1437
1438 dsi->clk = devm_clk_get(&pdev->dev, NULL);
1439 if (IS_ERR(dsi->clk)) {
1440 dev_err(&pdev->dev, "cannot get DSI clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001441 err = PTR_ERR(dsi->clk);
1442 goto reset;
Thierry Redingdec72732013-09-03 08:45:46 +02001443 }
1444
1445 err = clk_prepare_enable(dsi->clk);
1446 if (err < 0) {
1447 dev_err(&pdev->dev, "cannot enable DSI clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001448 goto reset;
Thierry Redingdec72732013-09-03 08:45:46 +02001449 }
1450
1451 dsi->clk_lp = devm_clk_get(&pdev->dev, "lp");
1452 if (IS_ERR(dsi->clk_lp)) {
1453 dev_err(&pdev->dev, "cannot get low-power clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001454 err = PTR_ERR(dsi->clk_lp);
1455 goto disable_clk;
Thierry Redingdec72732013-09-03 08:45:46 +02001456 }
1457
1458 err = clk_prepare_enable(dsi->clk_lp);
1459 if (err < 0) {
1460 dev_err(&pdev->dev, "cannot enable low-power clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001461 goto disable_clk;
Thierry Redingdec72732013-09-03 08:45:46 +02001462 }
1463
1464 dsi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1465 if (IS_ERR(dsi->clk_parent)) {
1466 dev_err(&pdev->dev, "cannot get parent clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001467 err = PTR_ERR(dsi->clk_parent);
1468 goto disable_clk_lp;
Thierry Redingdec72732013-09-03 08:45:46 +02001469 }
1470
Thierry Reding3b077af2014-03-14 14:07:50 +01001471 dsi->vdd = devm_regulator_get(&pdev->dev, "avdd-dsi-csi");
1472 if (IS_ERR(dsi->vdd)) {
1473 dev_err(&pdev->dev, "cannot get VDD supply\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001474 err = PTR_ERR(dsi->vdd);
1475 goto disable_clk_lp;
Thierry Reding3b077af2014-03-14 14:07:50 +01001476 }
1477
1478 err = regulator_enable(dsi->vdd);
1479 if (err < 0) {
1480 dev_err(&pdev->dev, "cannot enable VDD supply\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001481 goto disable_clk_lp;
Thierry Reding3b077af2014-03-14 14:07:50 +01001482 }
1483
Thierry Redingdec72732013-09-03 08:45:46 +02001484 err = tegra_dsi_setup_clocks(dsi);
1485 if (err < 0) {
1486 dev_err(&pdev->dev, "cannot setup clocks\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001487 goto disable_vdd;
Thierry Redingdec72732013-09-03 08:45:46 +02001488 }
1489
1490 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1491 dsi->regs = devm_ioremap_resource(&pdev->dev, regs);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001492 if (IS_ERR(dsi->regs)) {
1493 err = PTR_ERR(dsi->regs);
1494 goto disable_vdd;
1495 }
Thierry Redingdec72732013-09-03 08:45:46 +02001496
Thierry Redingdec72732013-09-03 08:45:46 +02001497 dsi->mipi = tegra_mipi_request(&pdev->dev);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001498 if (IS_ERR(dsi->mipi)) {
1499 err = PTR_ERR(dsi->mipi);
1500 goto disable_vdd;
1501 }
Thierry Redingdec72732013-09-03 08:45:46 +02001502
1503 dsi->host.ops = &tegra_dsi_host_ops;
1504 dsi->host.dev = &pdev->dev;
1505
1506 err = mipi_dsi_host_register(&dsi->host);
1507 if (err < 0) {
1508 dev_err(&pdev->dev, "failed to register DSI host: %d\n", err);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001509 goto mipi_free;
Thierry Redingdec72732013-09-03 08:45:46 +02001510 }
1511
1512 INIT_LIST_HEAD(&dsi->client.list);
1513 dsi->client.ops = &dsi_client_ops;
1514 dsi->client.dev = &pdev->dev;
1515
1516 err = host1x_client_register(&dsi->client);
1517 if (err < 0) {
1518 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1519 err);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001520 goto unregister;
Thierry Redingdec72732013-09-03 08:45:46 +02001521 }
1522
1523 platform_set_drvdata(pdev, dsi);
1524
1525 return 0;
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001526
1527unregister:
1528 mipi_dsi_host_unregister(&dsi->host);
1529mipi_free:
1530 tegra_mipi_free(dsi->mipi);
1531disable_vdd:
1532 regulator_disable(dsi->vdd);
1533disable_clk_lp:
1534 clk_disable_unprepare(dsi->clk_lp);
1535disable_clk:
1536 clk_disable_unprepare(dsi->clk);
1537reset:
1538 reset_control_assert(dsi->rst);
1539 return err;
Thierry Redingdec72732013-09-03 08:45:46 +02001540}
1541
1542static int tegra_dsi_remove(struct platform_device *pdev)
1543{
1544 struct tegra_dsi *dsi = platform_get_drvdata(pdev);
1545 int err;
1546
1547 err = host1x_client_unregister(&dsi->client);
1548 if (err < 0) {
1549 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1550 err);
1551 return err;
1552 }
1553
1554 mipi_dsi_host_unregister(&dsi->host);
1555 tegra_mipi_free(dsi->mipi);
1556
Thierry Reding3b077af2014-03-14 14:07:50 +01001557 regulator_disable(dsi->vdd);
Thierry Redingdec72732013-09-03 08:45:46 +02001558 clk_disable_unprepare(dsi->clk_lp);
1559 clk_disable_unprepare(dsi->clk);
Thierry Redingcb825d82014-03-14 14:25:43 +01001560 reset_control_assert(dsi->rst);
Thierry Redingdec72732013-09-03 08:45:46 +02001561
1562 err = tegra_output_remove(&dsi->output);
1563 if (err < 0) {
1564 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1565 return err;
1566 }
1567
1568 return 0;
1569}
1570
1571static const struct of_device_id tegra_dsi_of_match[] = {
1572 { .compatible = "nvidia,tegra114-dsi", },
1573 { },
1574};
Stephen Warrenef707282014-06-18 16:21:55 -06001575MODULE_DEVICE_TABLE(of, tegra_dsi_of_match);
Thierry Redingdec72732013-09-03 08:45:46 +02001576
1577struct platform_driver tegra_dsi_driver = {
1578 .driver = {
1579 .name = "tegra-dsi",
1580 .of_match_table = tegra_dsi_of_match,
1581 },
1582 .probe = tegra_dsi_probe,
1583 .remove = tegra_dsi_remove,
1584};