blob: 4c0dfe92402a6e59a2945719508cf71b99f476f9 [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_DISP_DISP_WIN_OPTIONS);
773 value &= ~DSI_ENABLE;
774 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Reding72d30282013-12-12 11:06:55 +0100775
Thierry Reding62b9e062014-11-21 17:33:33 +0100776 tegra_dc_commit(dc);
Thierry Redingdec72732013-09-03 08:45:46 +0200777 }
778
Thierry Reding563eff12014-11-13 14:44:27 +0100779 err = tegra_dsi_wait_idle(dsi, 100);
780 if (err < 0)
781 dev_dbg(dsi->dev, "failed to idle DSI: %d\n", err);
782
Thierry Reding92f0e072014-11-24 16:29:40 +0100783 tegra_dsi_soft_reset(dsi);
Thierry Reding563eff12014-11-13 14:44:27 +0100784 tegra_dsi_disable(dsi);
785
Thierry Reding334ae6b2014-03-14 14:15:10 +0100786 dsi->enabled = false;
787
Thierry Redingdec72732013-09-03 08:45:46 +0200788 return 0;
789}
790
Thierry Reding3f6b4062014-11-13 14:50:33 +0100791static void tegra_dsi_set_timeout(struct tegra_dsi *dsi, unsigned long bclk,
792 unsigned int vrefresh)
793{
794 unsigned int timeout;
795 u32 value;
796
797 /* one frame high-speed transmission timeout */
798 timeout = (bclk / vrefresh) / 512;
799 value = DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout);
800 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_0);
801
802 /* 2 ms peripheral timeout for panel */
803 timeout = 2 * bclk / 512 * 1000;
804 value = DSI_TIMEOUT_PR(timeout) | DSI_TIMEOUT_TA(0x2000);
805 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_1);
806
807 value = DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
808 tegra_dsi_writel(dsi, value, DSI_TO_TALLY);
Thierry Redinge94236c2014-10-07 16:10:24 +0200809
810 if (dsi->slave)
811 tegra_dsi_set_timeout(dsi->slave, bclk, vrefresh);
Thierry Reding3f6b4062014-11-13 14:50:33 +0100812}
813
Thierry Redingdec72732013-09-03 08:45:46 +0200814static int tegra_output_dsi_setup_clock(struct tegra_output *output,
Thierry Reding91eded92014-03-26 13:32:21 +0100815 struct clk *clk, unsigned long pclk,
816 unsigned int *divp)
Thierry Redingdec72732013-09-03 08:45:46 +0200817{
818 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
819 struct drm_display_mode *mode = &dc->base.mode;
Thierry Redingdec72732013-09-03 08:45:46 +0200820 struct tegra_dsi *dsi = to_dsi(output);
Thierry Redinge94236c2014-10-07 16:10:24 +0200821 unsigned int mul, div, vrefresh, lanes;
Thierry Reding3f6b4062014-11-13 14:50:33 +0100822 unsigned long bclk, plld;
Thierry Redingdec72732013-09-03 08:45:46 +0200823 int err;
824
Thierry Redinge94236c2014-10-07 16:10:24 +0200825 lanes = tegra_dsi_get_lanes(dsi);
826
Thierry Redingdec72732013-09-03 08:45:46 +0200827 err = tegra_dsi_get_muldiv(dsi->format, &mul, &div);
828 if (err < 0)
829 return err;
830
Thierry Redinge94236c2014-10-07 16:10:24 +0200831 DRM_DEBUG_KMS("mul: %u, div: %u, lanes: %u\n", mul, div, lanes);
Thierry Redingdec72732013-09-03 08:45:46 +0200832 vrefresh = drm_mode_vrefresh(mode);
Thierry Reding91eded92014-03-26 13:32:21 +0100833 DRM_DEBUG_KMS("vrefresh: %u\n", vrefresh);
Thierry Redingdec72732013-09-03 08:45:46 +0200834
Thierry Reding91eded92014-03-26 13:32:21 +0100835 /* compute byte clock */
Thierry Redinge94236c2014-10-07 16:10:24 +0200836 bclk = (pclk * mul) / (div * lanes);
Thierry Reding91eded92014-03-26 13:32:21 +0100837
838 /*
839 * Compute bit clock and round up to the next MHz.
840 */
Thierry Reding030611e2014-11-13 14:32:06 +0100841 plld = DIV_ROUND_UP(bclk * 8, USEC_PER_SEC) * USEC_PER_SEC;
Thierry Reding91eded92014-03-26 13:32:21 +0100842
843 /*
844 * We divide the frequency by two here, but we make up for that by
845 * setting the shift clock divider (further below) to half of the
846 * correct value.
847 */
848 plld /= 2;
Thierry Redingdec72732013-09-03 08:45:46 +0200849
850 err = clk_set_parent(clk, dsi->clk_parent);
851 if (err < 0) {
852 dev_err(dsi->dev, "failed to set parent clock: %d\n", err);
853 return err;
854 }
855
Thierry Reding91eded92014-03-26 13:32:21 +0100856 err = clk_set_rate(dsi->clk_parent, plld);
Thierry Redingdec72732013-09-03 08:45:46 +0200857 if (err < 0) {
858 dev_err(dsi->dev, "failed to set base clock rate to %lu Hz\n",
Thierry Reding91eded92014-03-26 13:32:21 +0100859 plld);
Thierry Redingdec72732013-09-03 08:45:46 +0200860 return err;
861 }
862
863 /*
Thierry Reding91eded92014-03-26 13:32:21 +0100864 * Derive pixel clock from bit clock using the shift clock divider.
865 * Note that this is only half of what we would expect, but we need
866 * that to make up for the fact that we divided the bit clock by a
867 * factor of two above.
868 *
869 * It's not clear exactly why this is necessary, but the display is
870 * not working properly otherwise. Perhaps the PLLs cannot generate
871 * frequencies sufficiently high.
872 */
Thierry Redinge94236c2014-10-07 16:10:24 +0200873 *divp = ((8 * mul) / (div * lanes)) - 2;
Thierry Reding91eded92014-03-26 13:32:21 +0100874
875 /*
Thierry Redingdec72732013-09-03 08:45:46 +0200876 * XXX: Move the below somewhere else so that we don't need to have
877 * access to the vrefresh in this function?
878 */
Thierry Reding3f6b4062014-11-13 14:50:33 +0100879 tegra_dsi_set_timeout(dsi, bclk, vrefresh);
Thierry Redingdec72732013-09-03 08:45:46 +0200880
Sean Paul7e3bc3a2014-10-07 16:04:42 +0200881 err = tegra_dsi_set_phy_timing(dsi);
882 if (err < 0)
883 return err;
884
Thierry Redingdec72732013-09-03 08:45:46 +0200885 return 0;
886}
887
888static int tegra_output_dsi_check_mode(struct tegra_output *output,
889 struct drm_display_mode *mode,
890 enum drm_mode_status *status)
891{
892 /*
893 * FIXME: For now, always assume that the mode is okay.
894 */
895
896 *status = MODE_OK;
897
898 return 0;
899}
900
901static const struct tegra_output_ops dsi_ops = {
902 .enable = tegra_output_dsi_enable,
903 .disable = tegra_output_dsi_disable,
904 .setup_clock = tegra_output_dsi_setup_clock,
905 .check_mode = tegra_output_dsi_check_mode,
906};
907
908static int tegra_dsi_pad_enable(struct tegra_dsi *dsi)
909{
Thierry Reding9c0b4ca2014-11-24 12:27:59 +0100910 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200911
912 value = DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
913 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_0);
914
915 return 0;
916}
917
918static int tegra_dsi_pad_calibrate(struct tegra_dsi *dsi)
919{
Thierry Reding183ef282014-11-13 14:27:29 +0100920 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200921
922 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_0);
923 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_1);
924 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_2);
925 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_3);
926 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_4);
927
928 /* start calibration */
929 tegra_dsi_pad_enable(dsi);
930
931 value = DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
932 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
933 DSI_PAD_OUT_CLK(0x0);
934 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_2);
935
936 return tegra_mipi_calibrate(dsi->mipi);
937}
938
939static int tegra_dsi_init(struct host1x_client *client)
940{
Thierry Reding9910f5c2014-05-22 09:57:15 +0200941 struct drm_device *drm = dev_get_drvdata(client->parent);
Thierry Redingdec72732013-09-03 08:45:46 +0200942 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
Thierry Redingdec72732013-09-03 08:45:46 +0200943 int err;
944
Thierry Reding201106d2014-11-24 16:31:48 +0100945 reset_control_deassert(dsi->rst);
946
947 err = tegra_dsi_pad_calibrate(dsi);
948 if (err < 0) {
949 dev_err(dsi->dev, "MIPI calibration failed: %d\n", err);
950 goto reset;
951 }
952
Thierry Redinge94236c2014-10-07 16:10:24 +0200953 /* Gangsters must not register their own outputs. */
954 if (!dsi->master) {
955 dsi->output.type = TEGRA_OUTPUT_DSI;
956 dsi->output.dev = client->dev;
957 dsi->output.ops = &dsi_ops;
Thierry Redingdec72732013-09-03 08:45:46 +0200958
Thierry Redinge94236c2014-10-07 16:10:24 +0200959 err = tegra_output_init(drm, &dsi->output);
960 if (err < 0) {
961 dev_err(client->dev, "output setup failed: %d\n", err);
962 return err;
963 }
Thierry Redingdec72732013-09-03 08:45:46 +0200964 }
965
966 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding9910f5c2014-05-22 09:57:15 +0200967 err = tegra_dsi_debugfs_init(dsi, drm->primary);
Thierry Redingdec72732013-09-03 08:45:46 +0200968 if (err < 0)
969 dev_err(dsi->dev, "debugfs setup failed: %d\n", err);
970 }
971
Thierry Redingdec72732013-09-03 08:45:46 +0200972 return 0;
Thierry Reding201106d2014-11-24 16:31:48 +0100973
974reset:
975 reset_control_assert(dsi->rst);
976 return err;
Thierry Redingdec72732013-09-03 08:45:46 +0200977}
978
979static int tegra_dsi_exit(struct host1x_client *client)
980{
981 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
982 int err;
983
984 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
985 err = tegra_dsi_debugfs_exit(dsi);
986 if (err < 0)
987 dev_err(dsi->dev, "debugfs cleanup failed: %d\n", err);
988 }
989
Thierry Redinge94236c2014-10-07 16:10:24 +0200990 if (!dsi->master) {
991 err = tegra_output_disable(&dsi->output);
992 if (err < 0) {
993 dev_err(client->dev, "output failed to disable: %d\n",
994 err);
995 return err;
996 }
Thierry Redingdec72732013-09-03 08:45:46 +0200997
Thierry Redinge94236c2014-10-07 16:10:24 +0200998 err = tegra_output_exit(&dsi->output);
999 if (err < 0) {
1000 dev_err(client->dev, "output cleanup failed: %d\n",
1001 err);
1002 return err;
1003 }
Thierry Redingdec72732013-09-03 08:45:46 +02001004 }
1005
Thierry Reding201106d2014-11-24 16:31:48 +01001006 reset_control_assert(dsi->rst);
1007
Thierry Redingdec72732013-09-03 08:45:46 +02001008 return 0;
1009}
1010
1011static const struct host1x_client_ops dsi_client_ops = {
1012 .init = tegra_dsi_init,
1013 .exit = tegra_dsi_exit,
1014};
1015
1016static int tegra_dsi_setup_clocks(struct tegra_dsi *dsi)
1017{
1018 struct clk *parent;
1019 int err;
1020
1021 parent = clk_get_parent(dsi->clk);
1022 if (!parent)
1023 return -EINVAL;
1024
1025 err = clk_set_parent(parent, dsi->clk_parent);
1026 if (err < 0)
1027 return err;
1028
1029 return 0;
1030}
1031
Thierry Reding0fffdf62014-11-07 17:25:26 +01001032static const char * const error_report[16] = {
1033 "SoT Error",
1034 "SoT Sync Error",
1035 "EoT Sync Error",
1036 "Escape Mode Entry Command Error",
1037 "Low-Power Transmit Sync Error",
1038 "Peripheral Timeout Error",
1039 "False Control Error",
1040 "Contention Detected",
1041 "ECC Error, single-bit",
1042 "ECC Error, multi-bit",
1043 "Checksum Error",
1044 "DSI Data Type Not Recognized",
1045 "DSI VC ID Invalid",
1046 "Invalid Transmission Length",
1047 "Reserved",
1048 "DSI Protocol Violation",
1049};
1050
1051static ssize_t tegra_dsi_read_response(struct tegra_dsi *dsi,
1052 const struct mipi_dsi_msg *msg,
1053 size_t count)
1054{
1055 u8 *rx = msg->rx_buf;
1056 unsigned int i, j, k;
1057 size_t size = 0;
1058 u16 errors;
1059 u32 value;
1060
1061 /* read and parse packet header */
1062 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1063
1064 switch (value & 0x3f) {
1065 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
1066 errors = (value >> 8) & 0xffff;
1067 dev_dbg(dsi->dev, "Acknowledge and error report: %04x\n",
1068 errors);
1069 for (i = 0; i < ARRAY_SIZE(error_report); i++)
1070 if (errors & BIT(i))
1071 dev_dbg(dsi->dev, " %2u: %s\n", i,
1072 error_report[i]);
1073 break;
1074
1075 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
1076 rx[0] = (value >> 8) & 0xff;
1077 size = 1;
1078 break;
1079
1080 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
1081 rx[0] = (value >> 8) & 0xff;
1082 rx[1] = (value >> 16) & 0xff;
1083 size = 2;
1084 break;
1085
1086 case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
1087 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
1088 break;
1089
1090 case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
1091 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
1092 break;
1093
1094 default:
1095 dev_err(dsi->dev, "unhandled response type: %02x\n",
1096 value & 0x3f);
1097 return -EPROTO;
1098 }
1099
1100 size = min(size, msg->rx_len);
1101
1102 if (msg->rx_buf && size > 0) {
1103 for (i = 0, j = 0; i < count - 1; i++, j += 4) {
1104 u8 *rx = msg->rx_buf + j;
1105
1106 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1107
1108 for (k = 0; k < 4 && (j + k) < msg->rx_len; k++)
1109 rx[j + k] = (value >> (k << 3)) & 0xff;
1110 }
1111 }
1112
1113 return size;
1114}
1115
1116static int tegra_dsi_transmit(struct tegra_dsi *dsi, unsigned long timeout)
1117{
1118 tegra_dsi_writel(dsi, DSI_TRIGGER_HOST, DSI_TRIGGER);
1119
1120 timeout = jiffies + msecs_to_jiffies(timeout);
1121
1122 while (time_before(jiffies, timeout)) {
1123 u32 value = tegra_dsi_readl(dsi, DSI_TRIGGER);
1124 if ((value & DSI_TRIGGER_HOST) == 0)
1125 return 0;
1126
1127 usleep_range(1000, 2000);
1128 }
1129
1130 DRM_DEBUG_KMS("timeout waiting for transmission to complete\n");
1131 return -ETIMEDOUT;
1132}
1133
1134static int tegra_dsi_wait_for_response(struct tegra_dsi *dsi,
1135 unsigned long timeout)
1136{
1137 timeout = jiffies + msecs_to_jiffies(250);
1138
1139 while (time_before(jiffies, timeout)) {
1140 u32 value = tegra_dsi_readl(dsi, DSI_STATUS);
1141 u8 count = value & 0x1f;
1142
1143 if (count > 0)
1144 return count;
1145
1146 usleep_range(1000, 2000);
1147 }
1148
1149 DRM_DEBUG_KMS("peripheral returned no data\n");
1150 return -ETIMEDOUT;
1151}
1152
1153static void tegra_dsi_writesl(struct tegra_dsi *dsi, unsigned long offset,
1154 const void *buffer, size_t size)
1155{
1156 const u8 *buf = buffer;
1157 size_t i, j;
1158 u32 value;
1159
1160 for (j = 0; j < size; j += 4) {
1161 value = 0;
1162
1163 for (i = 0; i < 4 && j + i < size; i++)
1164 value |= buf[j + i] << (i << 3);
1165
1166 tegra_dsi_writel(dsi, value, DSI_WR_DATA);
1167 }
1168}
1169
1170static ssize_t tegra_dsi_host_transfer(struct mipi_dsi_host *host,
1171 const struct mipi_dsi_msg *msg)
1172{
1173 struct tegra_dsi *dsi = host_to_tegra(host);
1174 struct mipi_dsi_packet packet;
1175 const u8 *header;
1176 size_t count;
1177 ssize_t err;
1178 u32 value;
1179
1180 err = mipi_dsi_create_packet(&packet, msg);
1181 if (err < 0)
1182 return err;
1183
1184 header = packet.header;
1185
1186 /* maximum FIFO depth is 1920 words */
1187 if (packet.size > dsi->video_fifo_depth * 4)
1188 return -ENOSPC;
1189
1190 /* reset underflow/overflow flags */
1191 value = tegra_dsi_readl(dsi, DSI_STATUS);
1192 if (value & (DSI_STATUS_UNDERFLOW | DSI_STATUS_OVERFLOW)) {
1193 value = DSI_HOST_CONTROL_FIFO_RESET;
1194 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1195 usleep_range(10, 20);
1196 }
1197
1198 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
1199 value |= DSI_POWER_CONTROL_ENABLE;
1200 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
1201
1202 usleep_range(5000, 10000);
1203
1204 value = DSI_HOST_CONTROL_CRC_RESET | DSI_HOST_CONTROL_TX_TRIG_HOST |
1205 DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC;
1206
1207 if ((msg->flags & MIPI_DSI_MSG_USE_LPM) == 0)
1208 value |= DSI_HOST_CONTROL_HS;
1209
1210 /*
1211 * The host FIFO has a maximum of 64 words, so larger transmissions
1212 * need to use the video FIFO.
1213 */
1214 if (packet.size > dsi->host_fifo_depth * 4)
1215 value |= DSI_HOST_CONTROL_FIFO_SEL;
1216
1217 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1218
1219 /*
1220 * For reads and messages with explicitly requested ACK, generate a
1221 * BTA sequence after the transmission of the packet.
1222 */
1223 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
1224 (msg->rx_buf && msg->rx_len > 0)) {
1225 value = tegra_dsi_readl(dsi, DSI_HOST_CONTROL);
1226 value |= DSI_HOST_CONTROL_PKT_BTA;
1227 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1228 }
1229
1230 value = DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE;
1231 tegra_dsi_writel(dsi, value, DSI_CONTROL);
1232
1233 /* write packet header, ECC is generated by hardware */
1234 value = header[2] << 16 | header[1] << 8 | header[0];
1235 tegra_dsi_writel(dsi, value, DSI_WR_DATA);
1236
1237 /* write payload (if any) */
1238 if (packet.payload_length > 0)
1239 tegra_dsi_writesl(dsi, DSI_WR_DATA, packet.payload,
1240 packet.payload_length);
1241
1242 err = tegra_dsi_transmit(dsi, 250);
1243 if (err < 0)
1244 return err;
1245
1246 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
1247 (msg->rx_buf && msg->rx_len > 0)) {
1248 err = tegra_dsi_wait_for_response(dsi, 250);
1249 if (err < 0)
1250 return err;
1251
1252 count = err;
1253
1254 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1255 switch (value) {
1256 case 0x84:
1257 /*
1258 dev_dbg(dsi->dev, "ACK\n");
1259 */
1260 break;
1261
1262 case 0x87:
1263 /*
1264 dev_dbg(dsi->dev, "ESCAPE\n");
1265 */
1266 break;
1267
1268 default:
1269 dev_err(dsi->dev, "unknown status: %08x\n", value);
1270 break;
1271 }
1272
1273 if (count > 1) {
1274 err = tegra_dsi_read_response(dsi, msg, count);
1275 if (err < 0)
1276 dev_err(dsi->dev,
1277 "failed to parse response: %zd\n",
1278 err);
1279 else {
1280 /*
1281 * For read commands, return the number of
1282 * bytes returned by the peripheral.
1283 */
1284 count = err;
1285 }
1286 }
1287 } else {
1288 /*
1289 * For write commands, we have transmitted the 4-byte header
1290 * plus the variable-length payload.
1291 */
1292 count = 4 + packet.payload_length;
1293 }
1294
1295 return count;
1296}
1297
Thierry Redinge94236c2014-10-07 16:10:24 +02001298static int tegra_dsi_ganged_setup(struct tegra_dsi *dsi)
1299{
1300 struct clk *parent;
1301 int err;
1302
1303 /* make sure both DSI controllers share the same PLL */
1304 parent = clk_get_parent(dsi->slave->clk);
1305 if (!parent)
1306 return -EINVAL;
1307
1308 err = clk_set_parent(parent, dsi->clk_parent);
1309 if (err < 0)
1310 return err;
1311
1312 return 0;
1313}
1314
Thierry Redingdec72732013-09-03 08:45:46 +02001315static int tegra_dsi_host_attach(struct mipi_dsi_host *host,
1316 struct mipi_dsi_device *device)
1317{
1318 struct tegra_dsi *dsi = host_to_tegra(host);
Thierry Redingdec72732013-09-03 08:45:46 +02001319
Thierry Reding17297a22014-03-14 14:13:15 +01001320 dsi->flags = device->mode_flags;
Thierry Redingdec72732013-09-03 08:45:46 +02001321 dsi->format = device->format;
1322 dsi->lanes = device->lanes;
1323
Thierry Redinge94236c2014-10-07 16:10:24 +02001324 if (dsi->slave) {
1325 int err;
1326
1327 dev_dbg(dsi->dev, "attaching dual-channel device %s\n",
1328 dev_name(&device->dev));
1329
1330 err = tegra_dsi_ganged_setup(dsi);
1331 if (err < 0) {
1332 dev_err(dsi->dev, "failed to set up ganged mode: %d\n",
1333 err);
1334 return err;
1335 }
1336 }
1337
1338 /*
1339 * Slaves don't have a panel associated with them, so they provide
1340 * merely the second channel.
1341 */
1342 if (!dsi->master) {
1343 struct tegra_output *output = &dsi->output;
1344
1345 output->panel = of_drm_find_panel(device->dev.of_node);
1346 if (output->panel && output->connector.dev) {
1347 drm_panel_attach(output->panel, &output->connector);
Thierry Redingdec72732013-09-03 08:45:46 +02001348 drm_helper_hpd_irq_event(output->connector.dev);
Thierry Redinge94236c2014-10-07 16:10:24 +02001349 }
Thierry Redingdec72732013-09-03 08:45:46 +02001350 }
1351
1352 return 0;
1353}
1354
1355static int tegra_dsi_host_detach(struct mipi_dsi_host *host,
1356 struct mipi_dsi_device *device)
1357{
1358 struct tegra_dsi *dsi = host_to_tegra(host);
1359 struct tegra_output *output = &dsi->output;
1360
1361 if (output->panel && &device->dev == output->panel->dev) {
Thierry Redingba3df972014-11-13 14:54:01 +01001362 output->panel = NULL;
1363
Thierry Redingdec72732013-09-03 08:45:46 +02001364 if (output->connector.dev)
1365 drm_helper_hpd_irq_event(output->connector.dev);
Thierry Redingdec72732013-09-03 08:45:46 +02001366 }
1367
1368 return 0;
1369}
1370
1371static const struct mipi_dsi_host_ops tegra_dsi_host_ops = {
1372 .attach = tegra_dsi_host_attach,
1373 .detach = tegra_dsi_host_detach,
Thierry Reding0fffdf62014-11-07 17:25:26 +01001374 .transfer = tegra_dsi_host_transfer,
Thierry Redingdec72732013-09-03 08:45:46 +02001375};
1376
Thierry Redinge94236c2014-10-07 16:10:24 +02001377static int tegra_dsi_ganged_probe(struct tegra_dsi *dsi)
1378{
1379 struct device_node *np;
1380
1381 np = of_parse_phandle(dsi->dev->of_node, "nvidia,ganged-mode", 0);
1382 if (np) {
1383 struct platform_device *gangster = of_find_device_by_node(np);
1384
1385 dsi->slave = platform_get_drvdata(gangster);
1386 of_node_put(np);
1387
1388 if (!dsi->slave)
1389 return -EPROBE_DEFER;
1390
1391 dsi->slave->master = dsi;
1392 }
1393
1394 return 0;
1395}
1396
Thierry Redingdec72732013-09-03 08:45:46 +02001397static int tegra_dsi_probe(struct platform_device *pdev)
1398{
1399 struct tegra_dsi *dsi;
1400 struct resource *regs;
1401 int err;
1402
1403 dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL);
1404 if (!dsi)
1405 return -ENOMEM;
1406
1407 dsi->output.dev = dsi->dev = &pdev->dev;
Thierry Reding976cebc2014-08-06 09:14:28 +02001408 dsi->video_fifo_depth = 1920;
1409 dsi->host_fifo_depth = 64;
Thierry Redingdec72732013-09-03 08:45:46 +02001410
Thierry Redinge94236c2014-10-07 16:10:24 +02001411 err = tegra_dsi_ganged_probe(dsi);
1412 if (err < 0)
1413 return err;
1414
Thierry Redingdec72732013-09-03 08:45:46 +02001415 err = tegra_output_probe(&dsi->output);
1416 if (err < 0)
1417 return err;
1418
Thierry Redingba3df972014-11-13 14:54:01 +01001419 dsi->output.connector.polled = DRM_CONNECTOR_POLL_HPD;
1420
Thierry Redingdec72732013-09-03 08:45:46 +02001421 /*
1422 * Assume these values by default. When a DSI peripheral driver
1423 * attaches to the DSI host, the parameters will be taken from
1424 * the attached device.
1425 */
Thierry Reding17297a22014-03-14 14:13:15 +01001426 dsi->flags = MIPI_DSI_MODE_VIDEO;
Thierry Redingdec72732013-09-03 08:45:46 +02001427 dsi->format = MIPI_DSI_FMT_RGB888;
1428 dsi->lanes = 4;
1429
1430 dsi->rst = devm_reset_control_get(&pdev->dev, "dsi");
1431 if (IS_ERR(dsi->rst))
1432 return PTR_ERR(dsi->rst);
1433
1434 dsi->clk = devm_clk_get(&pdev->dev, NULL);
1435 if (IS_ERR(dsi->clk)) {
1436 dev_err(&pdev->dev, "cannot get DSI clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001437 err = PTR_ERR(dsi->clk);
1438 goto reset;
Thierry Redingdec72732013-09-03 08:45:46 +02001439 }
1440
1441 err = clk_prepare_enable(dsi->clk);
1442 if (err < 0) {
1443 dev_err(&pdev->dev, "cannot enable DSI clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001444 goto reset;
Thierry Redingdec72732013-09-03 08:45:46 +02001445 }
1446
1447 dsi->clk_lp = devm_clk_get(&pdev->dev, "lp");
1448 if (IS_ERR(dsi->clk_lp)) {
1449 dev_err(&pdev->dev, "cannot get low-power clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001450 err = PTR_ERR(dsi->clk_lp);
1451 goto disable_clk;
Thierry Redingdec72732013-09-03 08:45:46 +02001452 }
1453
1454 err = clk_prepare_enable(dsi->clk_lp);
1455 if (err < 0) {
1456 dev_err(&pdev->dev, "cannot enable low-power clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001457 goto disable_clk;
Thierry Redingdec72732013-09-03 08:45:46 +02001458 }
1459
1460 dsi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1461 if (IS_ERR(dsi->clk_parent)) {
1462 dev_err(&pdev->dev, "cannot get parent clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001463 err = PTR_ERR(dsi->clk_parent);
1464 goto disable_clk_lp;
Thierry Redingdec72732013-09-03 08:45:46 +02001465 }
1466
Thierry Reding3b077af2014-03-14 14:07:50 +01001467 dsi->vdd = devm_regulator_get(&pdev->dev, "avdd-dsi-csi");
1468 if (IS_ERR(dsi->vdd)) {
1469 dev_err(&pdev->dev, "cannot get VDD supply\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001470 err = PTR_ERR(dsi->vdd);
1471 goto disable_clk_lp;
Thierry Reding3b077af2014-03-14 14:07:50 +01001472 }
1473
1474 err = regulator_enable(dsi->vdd);
1475 if (err < 0) {
1476 dev_err(&pdev->dev, "cannot enable VDD supply\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001477 goto disable_clk_lp;
Thierry Reding3b077af2014-03-14 14:07:50 +01001478 }
1479
Thierry Redingdec72732013-09-03 08:45:46 +02001480 err = tegra_dsi_setup_clocks(dsi);
1481 if (err < 0) {
1482 dev_err(&pdev->dev, "cannot setup clocks\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001483 goto disable_vdd;
Thierry Redingdec72732013-09-03 08:45:46 +02001484 }
1485
1486 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1487 dsi->regs = devm_ioremap_resource(&pdev->dev, regs);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001488 if (IS_ERR(dsi->regs)) {
1489 err = PTR_ERR(dsi->regs);
1490 goto disable_vdd;
1491 }
Thierry Redingdec72732013-09-03 08:45:46 +02001492
Thierry Redingdec72732013-09-03 08:45:46 +02001493 dsi->mipi = tegra_mipi_request(&pdev->dev);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001494 if (IS_ERR(dsi->mipi)) {
1495 err = PTR_ERR(dsi->mipi);
1496 goto disable_vdd;
1497 }
Thierry Redingdec72732013-09-03 08:45:46 +02001498
1499 dsi->host.ops = &tegra_dsi_host_ops;
1500 dsi->host.dev = &pdev->dev;
1501
1502 err = mipi_dsi_host_register(&dsi->host);
1503 if (err < 0) {
1504 dev_err(&pdev->dev, "failed to register DSI host: %d\n", err);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001505 goto mipi_free;
Thierry Redingdec72732013-09-03 08:45:46 +02001506 }
1507
1508 INIT_LIST_HEAD(&dsi->client.list);
1509 dsi->client.ops = &dsi_client_ops;
1510 dsi->client.dev = &pdev->dev;
1511
1512 err = host1x_client_register(&dsi->client);
1513 if (err < 0) {
1514 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1515 err);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001516 goto unregister;
Thierry Redingdec72732013-09-03 08:45:46 +02001517 }
1518
1519 platform_set_drvdata(pdev, dsi);
1520
1521 return 0;
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001522
1523unregister:
1524 mipi_dsi_host_unregister(&dsi->host);
1525mipi_free:
1526 tegra_mipi_free(dsi->mipi);
1527disable_vdd:
1528 regulator_disable(dsi->vdd);
1529disable_clk_lp:
1530 clk_disable_unprepare(dsi->clk_lp);
1531disable_clk:
1532 clk_disable_unprepare(dsi->clk);
1533reset:
1534 reset_control_assert(dsi->rst);
1535 return err;
Thierry Redingdec72732013-09-03 08:45:46 +02001536}
1537
1538static int tegra_dsi_remove(struct platform_device *pdev)
1539{
1540 struct tegra_dsi *dsi = platform_get_drvdata(pdev);
1541 int err;
1542
1543 err = host1x_client_unregister(&dsi->client);
1544 if (err < 0) {
1545 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1546 err);
1547 return err;
1548 }
1549
1550 mipi_dsi_host_unregister(&dsi->host);
1551 tegra_mipi_free(dsi->mipi);
1552
Thierry Reding3b077af2014-03-14 14:07:50 +01001553 regulator_disable(dsi->vdd);
Thierry Redingdec72732013-09-03 08:45:46 +02001554 clk_disable_unprepare(dsi->clk_lp);
1555 clk_disable_unprepare(dsi->clk);
Thierry Redingcb825d82014-03-14 14:25:43 +01001556 reset_control_assert(dsi->rst);
Thierry Redingdec72732013-09-03 08:45:46 +02001557
1558 err = tegra_output_remove(&dsi->output);
1559 if (err < 0) {
1560 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1561 return err;
1562 }
1563
1564 return 0;
1565}
1566
1567static const struct of_device_id tegra_dsi_of_match[] = {
1568 { .compatible = "nvidia,tegra114-dsi", },
1569 { },
1570};
Stephen Warrenef707282014-06-18 16:21:55 -06001571MODULE_DEVICE_TABLE(of, tegra_dsi_of_match);
Thierry Redingdec72732013-09-03 08:45:46 +02001572
1573struct platform_driver tegra_dsi_driver = {
1574 .driver = {
1575 .name = "tegra-dsi",
1576 .of_match_table = tegra_dsi_of_match,
1577 },
1578 .probe = tegra_dsi_probe,
1579 .remove = tegra_dsi_remove,
1580};