blob: b91d9e4016bc3ff052185da670bed5c4185bd803 [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>
14#include <linux/platform_device.h>
15#include <linux/reset.h>
16
Thierry Reding3b077af2014-03-14 14:07:50 +010017#include <linux/regulator/consumer.h>
18
Thierry Redingdec72732013-09-03 08:45:46 +020019#include <drm/drm_mipi_dsi.h>
20#include <drm/drm_panel.h>
21
22#include <video/mipi_display.h>
23
24#include "dc.h"
25#include "drm.h"
26#include "dsi.h"
27#include "mipi-phy.h"
28
Thierry Redingdec72732013-09-03 08:45:46 +020029struct tegra_dsi {
30 struct host1x_client client;
31 struct tegra_output output;
32 struct device *dev;
33
34 void __iomem *regs;
35
36 struct reset_control *rst;
37 struct clk *clk_parent;
38 struct clk *clk_lp;
39 struct clk *clk;
40
41 struct drm_info_list *debugfs_files;
42 struct drm_minor *minor;
43 struct dentry *debugfs;
44
Thierry Reding17297a22014-03-14 14:13:15 +010045 unsigned long flags;
Thierry Redingdec72732013-09-03 08:45:46 +020046 enum mipi_dsi_pixel_format format;
47 unsigned int lanes;
48
49 struct tegra_mipi_device *mipi;
50 struct mipi_dsi_host host;
Thierry Reding3b077af2014-03-14 14:07:50 +010051
52 struct regulator *vdd;
Thierry Reding334ae6b2014-03-14 14:15:10 +010053 bool enabled;
Thierry Reding976cebc2014-08-06 09:14:28 +020054
55 unsigned int video_fifo_depth;
56 unsigned int host_fifo_depth;
Thierry Redingdec72732013-09-03 08:45:46 +020057};
58
59static inline struct tegra_dsi *
60host1x_client_to_dsi(struct host1x_client *client)
61{
62 return container_of(client, struct tegra_dsi, client);
63}
64
65static inline struct tegra_dsi *host_to_tegra(struct mipi_dsi_host *host)
66{
67 return container_of(host, struct tegra_dsi, host);
68}
69
70static inline struct tegra_dsi *to_dsi(struct tegra_output *output)
71{
72 return container_of(output, struct tegra_dsi, output);
73}
74
75static inline unsigned long tegra_dsi_readl(struct tegra_dsi *dsi,
76 unsigned long reg)
77{
78 return readl(dsi->regs + (reg << 2));
79}
80
81static inline void tegra_dsi_writel(struct tegra_dsi *dsi, unsigned long value,
82 unsigned long reg)
83{
84 writel(value, dsi->regs + (reg << 2));
85}
86
87static int tegra_dsi_show_regs(struct seq_file *s, void *data)
88{
89 struct drm_info_node *node = s->private;
90 struct tegra_dsi *dsi = node->info_ent->data;
91
92#define DUMP_REG(name) \
93 seq_printf(s, "%-32s %#05x %08lx\n", #name, name, \
94 tegra_dsi_readl(dsi, name))
95
96 DUMP_REG(DSI_INCR_SYNCPT);
97 DUMP_REG(DSI_INCR_SYNCPT_CONTROL);
98 DUMP_REG(DSI_INCR_SYNCPT_ERROR);
99 DUMP_REG(DSI_CTXSW);
100 DUMP_REG(DSI_RD_DATA);
101 DUMP_REG(DSI_WR_DATA);
102 DUMP_REG(DSI_POWER_CONTROL);
103 DUMP_REG(DSI_INT_ENABLE);
104 DUMP_REG(DSI_INT_STATUS);
105 DUMP_REG(DSI_INT_MASK);
106 DUMP_REG(DSI_HOST_CONTROL);
107 DUMP_REG(DSI_CONTROL);
108 DUMP_REG(DSI_SOL_DELAY);
109 DUMP_REG(DSI_MAX_THRESHOLD);
110 DUMP_REG(DSI_TRIGGER);
111 DUMP_REG(DSI_TX_CRC);
112 DUMP_REG(DSI_STATUS);
113
114 DUMP_REG(DSI_INIT_SEQ_CONTROL);
115 DUMP_REG(DSI_INIT_SEQ_DATA_0);
116 DUMP_REG(DSI_INIT_SEQ_DATA_1);
117 DUMP_REG(DSI_INIT_SEQ_DATA_2);
118 DUMP_REG(DSI_INIT_SEQ_DATA_3);
119 DUMP_REG(DSI_INIT_SEQ_DATA_4);
120 DUMP_REG(DSI_INIT_SEQ_DATA_5);
121 DUMP_REG(DSI_INIT_SEQ_DATA_6);
122 DUMP_REG(DSI_INIT_SEQ_DATA_7);
123
124 DUMP_REG(DSI_PKT_SEQ_0_LO);
125 DUMP_REG(DSI_PKT_SEQ_0_HI);
126 DUMP_REG(DSI_PKT_SEQ_1_LO);
127 DUMP_REG(DSI_PKT_SEQ_1_HI);
128 DUMP_REG(DSI_PKT_SEQ_2_LO);
129 DUMP_REG(DSI_PKT_SEQ_2_HI);
130 DUMP_REG(DSI_PKT_SEQ_3_LO);
131 DUMP_REG(DSI_PKT_SEQ_3_HI);
132 DUMP_REG(DSI_PKT_SEQ_4_LO);
133 DUMP_REG(DSI_PKT_SEQ_4_HI);
134 DUMP_REG(DSI_PKT_SEQ_5_LO);
135 DUMP_REG(DSI_PKT_SEQ_5_HI);
136
137 DUMP_REG(DSI_DCS_CMDS);
138
139 DUMP_REG(DSI_PKT_LEN_0_1);
140 DUMP_REG(DSI_PKT_LEN_2_3);
141 DUMP_REG(DSI_PKT_LEN_4_5);
142 DUMP_REG(DSI_PKT_LEN_6_7);
143
144 DUMP_REG(DSI_PHY_TIMING_0);
145 DUMP_REG(DSI_PHY_TIMING_1);
146 DUMP_REG(DSI_PHY_TIMING_2);
147 DUMP_REG(DSI_BTA_TIMING);
148
149 DUMP_REG(DSI_TIMEOUT_0);
150 DUMP_REG(DSI_TIMEOUT_1);
151 DUMP_REG(DSI_TO_TALLY);
152
153 DUMP_REG(DSI_PAD_CONTROL_0);
154 DUMP_REG(DSI_PAD_CONTROL_CD);
155 DUMP_REG(DSI_PAD_CD_STATUS);
156 DUMP_REG(DSI_VIDEO_MODE_CONTROL);
157 DUMP_REG(DSI_PAD_CONTROL_1);
158 DUMP_REG(DSI_PAD_CONTROL_2);
159 DUMP_REG(DSI_PAD_CONTROL_3);
160 DUMP_REG(DSI_PAD_CONTROL_4);
161
162 DUMP_REG(DSI_GANGED_MODE_CONTROL);
163 DUMP_REG(DSI_GANGED_MODE_START);
164 DUMP_REG(DSI_GANGED_MODE_SIZE);
165
166 DUMP_REG(DSI_RAW_DATA_BYTE_COUNT);
167 DUMP_REG(DSI_ULTRA_LOW_POWER_CONTROL);
168
169 DUMP_REG(DSI_INIT_SEQ_DATA_8);
170 DUMP_REG(DSI_INIT_SEQ_DATA_9);
171 DUMP_REG(DSI_INIT_SEQ_DATA_10);
172 DUMP_REG(DSI_INIT_SEQ_DATA_11);
173 DUMP_REG(DSI_INIT_SEQ_DATA_12);
174 DUMP_REG(DSI_INIT_SEQ_DATA_13);
175 DUMP_REG(DSI_INIT_SEQ_DATA_14);
176 DUMP_REG(DSI_INIT_SEQ_DATA_15);
177
178#undef DUMP_REG
179
180 return 0;
181}
182
183static struct drm_info_list debugfs_files[] = {
184 { "regs", tegra_dsi_show_regs, 0, NULL },
185};
186
187static int tegra_dsi_debugfs_init(struct tegra_dsi *dsi,
188 struct drm_minor *minor)
189{
190 const char *name = dev_name(dsi->dev);
191 unsigned int i;
192 int err;
193
194 dsi->debugfs = debugfs_create_dir(name, minor->debugfs_root);
195 if (!dsi->debugfs)
196 return -ENOMEM;
197
198 dsi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
199 GFP_KERNEL);
200 if (!dsi->debugfs_files) {
201 err = -ENOMEM;
202 goto remove;
203 }
204
205 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
206 dsi->debugfs_files[i].data = dsi;
207
208 err = drm_debugfs_create_files(dsi->debugfs_files,
209 ARRAY_SIZE(debugfs_files),
210 dsi->debugfs, minor);
211 if (err < 0)
212 goto free;
213
214 dsi->minor = minor;
215
216 return 0;
217
218free:
219 kfree(dsi->debugfs_files);
220 dsi->debugfs_files = NULL;
221remove:
222 debugfs_remove(dsi->debugfs);
223 dsi->debugfs = NULL;
224
225 return err;
226}
227
228static int tegra_dsi_debugfs_exit(struct tegra_dsi *dsi)
229{
230 drm_debugfs_remove_files(dsi->debugfs_files, ARRAY_SIZE(debugfs_files),
231 dsi->minor);
232 dsi->minor = NULL;
233
234 kfree(dsi->debugfs_files);
235 dsi->debugfs_files = NULL;
236
237 debugfs_remove(dsi->debugfs);
238 dsi->debugfs = NULL;
239
240 return 0;
241}
242
243#define PKT_ID0(id) ((((id) & 0x3f) << 3) | (1 << 9))
244#define PKT_LEN0(len) (((len) & 0x07) << 0)
245#define PKT_ID1(id) ((((id) & 0x3f) << 13) | (1 << 19))
246#define PKT_LEN1(len) (((len) & 0x07) << 10)
247#define PKT_ID2(id) ((((id) & 0x3f) << 23) | (1 << 29))
248#define PKT_LEN2(len) (((len) & 0x07) << 20)
249
250#define PKT_LP (1 << 30)
251#define NUM_PKT_SEQ 12
252
Thierry Reding17297a22014-03-14 14:13:15 +0100253/*
254 * non-burst mode with sync pulses
255 */
256static const u32 pkt_seq_video_non_burst_sync_pulses[NUM_PKT_SEQ] = {
Thierry Redingdec72732013-09-03 08:45:46 +0200257 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
258 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
259 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
260 PKT_LP,
261 [ 1] = 0,
262 [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END) | PKT_LEN0(0) |
263 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
264 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
265 PKT_LP,
266 [ 3] = 0,
267 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
268 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
269 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
270 PKT_LP,
271 [ 5] = 0,
272 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
273 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
274 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
275 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
276 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
277 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
278 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
279 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
280 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
281 PKT_LP,
282 [ 9] = 0,
283 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
284 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
285 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
286 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
287 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
288 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
289};
290
Thierry Reding17297a22014-03-14 14:13:15 +0100291/*
292 * non-burst mode with sync events
293 */
294static const u32 pkt_seq_video_non_burst_sync_events[NUM_PKT_SEQ] = {
295 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
296 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
297 PKT_LP,
298 [ 1] = 0,
299 [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
300 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
301 PKT_LP,
302 [ 3] = 0,
303 [ 4] = 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 [ 5] = 0,
307 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
308 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
309 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
310 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
311 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
312 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
313 PKT_LP,
314 [ 9] = 0,
315 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
316 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
317 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
318 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
319};
320
Thierry Redingdec72732013-09-03 08:45:46 +0200321static int tegra_dsi_set_phy_timing(struct tegra_dsi *dsi)
322{
323 struct mipi_dphy_timing timing;
324 unsigned long value, period;
325 long rate;
326 int err;
327
328 rate = clk_get_rate(dsi->clk);
329 if (rate < 0)
330 return rate;
331
332 period = DIV_ROUND_CLOSEST(1000000000UL, rate * 2);
333
334 err = mipi_dphy_timing_get_default(&timing, period);
335 if (err < 0)
336 return err;
337
338 err = mipi_dphy_timing_validate(&timing, period);
339 if (err < 0) {
340 dev_err(dsi->dev, "failed to validate D-PHY timing: %d\n", err);
341 return err;
342 }
343
344 /*
345 * The D-PHY timing fields below are expressed in byte-clock cycles,
346 * so multiply the period by 8.
347 */
348 period *= 8;
349
350 value = DSI_TIMING_FIELD(timing.hsexit, period, 1) << 24 |
351 DSI_TIMING_FIELD(timing.hstrail, period, 0) << 16 |
352 DSI_TIMING_FIELD(timing.hszero, period, 3) << 8 |
353 DSI_TIMING_FIELD(timing.hsprepare, period, 1);
354 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_0);
355
356 value = DSI_TIMING_FIELD(timing.clktrail, period, 1) << 24 |
357 DSI_TIMING_FIELD(timing.clkpost, period, 1) << 16 |
358 DSI_TIMING_FIELD(timing.clkzero, period, 1) << 8 |
359 DSI_TIMING_FIELD(timing.lpx, period, 1);
360 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_1);
361
362 value = DSI_TIMING_FIELD(timing.clkprepare, period, 1) << 16 |
363 DSI_TIMING_FIELD(timing.clkpre, period, 1) << 8 |
364 DSI_TIMING_FIELD(0xff * period, period, 0) << 0;
365 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_2);
366
367 value = DSI_TIMING_FIELD(timing.taget, period, 1) << 16 |
368 DSI_TIMING_FIELD(timing.tasure, period, 1) << 8 |
369 DSI_TIMING_FIELD(timing.tago, period, 1);
370 tegra_dsi_writel(dsi, value, DSI_BTA_TIMING);
371
372 return 0;
373}
374
375static int tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format,
376 unsigned int *mulp, unsigned int *divp)
377{
378 switch (format) {
379 case MIPI_DSI_FMT_RGB666_PACKED:
380 case MIPI_DSI_FMT_RGB888:
381 *mulp = 3;
382 *divp = 1;
383 break;
384
385 case MIPI_DSI_FMT_RGB565:
386 *mulp = 2;
387 *divp = 1;
388 break;
389
390 case MIPI_DSI_FMT_RGB666:
391 *mulp = 9;
392 *divp = 4;
393 break;
394
395 default:
396 return -EINVAL;
397 }
398
399 return 0;
400}
401
Thierry Redingf7d68892014-03-13 08:50:39 +0100402static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format,
403 enum tegra_dsi_format *fmt)
404{
405 switch (format) {
406 case MIPI_DSI_FMT_RGB888:
407 *fmt = TEGRA_DSI_FORMAT_24P;
408 break;
409
410 case MIPI_DSI_FMT_RGB666:
411 *fmt = TEGRA_DSI_FORMAT_18NP;
412 break;
413
414 case MIPI_DSI_FMT_RGB666_PACKED:
415 *fmt = TEGRA_DSI_FORMAT_18P;
416 break;
417
418 case MIPI_DSI_FMT_RGB565:
419 *fmt = TEGRA_DSI_FORMAT_16P;
420 break;
421
422 default:
423 return -EINVAL;
424 }
425
426 return 0;
427}
428
Thierry Reding563eff12014-11-13 14:44:27 +0100429static void tegra_dsi_enable(struct tegra_dsi *dsi)
Thierry Redingdec72732013-09-03 08:45:46 +0200430{
Thierry Reding563eff12014-11-13 14:44:27 +0100431 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200432
Thierry Reding563eff12014-11-13 14:44:27 +0100433 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
434 value |= DSI_POWER_CONTROL_ENABLE;
435 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
436}
437
438static int tegra_dsi_configure(struct tegra_dsi *dsi, unsigned int pipe,
439 const struct drm_display_mode *mode)
440{
441 unsigned int hact, hsw, hbp, hfp, i, mul, div;
442 enum tegra_dsi_format format;
443 const u32 *pkt_seq;
444 u32 value;
445 int err;
Thierry Reding334ae6b2014-03-14 14:15:10 +0100446
Thierry Reding17297a22014-03-14 14:13:15 +0100447 if (dsi->flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) {
448 DRM_DEBUG_KMS("Non-burst video mode with sync pulses\n");
449 pkt_seq = pkt_seq_video_non_burst_sync_pulses;
450 } else {
451 DRM_DEBUG_KMS("Non-burst video mode with sync events\n");
452 pkt_seq = pkt_seq_video_non_burst_sync_events;
453 }
454
Thierry Redingdec72732013-09-03 08:45:46 +0200455 err = tegra_dsi_get_muldiv(dsi->format, &mul, &div);
456 if (err < 0)
457 return err;
458
Thierry Redingf7d68892014-03-13 08:50:39 +0100459 err = tegra_dsi_get_format(dsi->format, &format);
460 if (err < 0)
461 return err;
462
Thierry Redingf7d68892014-03-13 08:50:39 +0100463 value = DSI_CONTROL_CHANNEL(0) | DSI_CONTROL_FORMAT(format) |
Thierry Redingdec72732013-09-03 08:45:46 +0200464 DSI_CONTROL_LANES(dsi->lanes - 1) |
Thierry Reding563eff12014-11-13 14:44:27 +0100465 DSI_CONTROL_SOURCE(pipe);
Thierry Redingdec72732013-09-03 08:45:46 +0200466 tegra_dsi_writel(dsi, value, DSI_CONTROL);
467
Thierry Reding976cebc2014-08-06 09:14:28 +0200468 tegra_dsi_writel(dsi, dsi->video_fifo_depth, DSI_MAX_THRESHOLD);
Thierry Redingdec72732013-09-03 08:45:46 +0200469
Thierry Reding563eff12014-11-13 14:44:27 +0100470 value = DSI_HOST_CONTROL_HS;
Thierry Redingdec72732013-09-03 08:45:46 +0200471 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
472
473 value = tegra_dsi_readl(dsi, DSI_CONTROL);
Thierry Reding563eff12014-11-13 14:44:27 +0100474
Alexandre Courbot0c6b1e42014-07-08 21:32:13 +0900475 if (dsi->flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)
476 value |= DSI_CONTROL_HS_CLK_CTRL;
Thierry Reding563eff12014-11-13 14:44:27 +0100477
Thierry Redingdec72732013-09-03 08:45:46 +0200478 value &= ~DSI_CONTROL_TX_TRIG(3);
479 value &= ~DSI_CONTROL_DCS_ENABLE;
480 value |= DSI_CONTROL_VIDEO_ENABLE;
481 value &= ~DSI_CONTROL_HOST_ENABLE;
482 tegra_dsi_writel(dsi, value, DSI_CONTROL);
483
484 err = tegra_dsi_set_phy_timing(dsi);
485 if (err < 0)
486 return err;
487
488 for (i = 0; i < NUM_PKT_SEQ; i++)
489 tegra_dsi_writel(dsi, pkt_seq[i], DSI_PKT_SEQ_0_LO + i);
490
491 /* horizontal active pixels */
492 hact = mode->hdisplay * mul / div;
493
494 /* horizontal sync width */
495 hsw = (mode->hsync_end - mode->hsync_start) * mul / div;
496 hsw -= 10;
497
498 /* horizontal back porch */
499 hbp = (mode->htotal - mode->hsync_end) * mul / div;
500 hbp -= 14;
501
502 /* horizontal front porch */
503 hfp = (mode->hsync_start - mode->hdisplay) * mul / div;
504 hfp -= 8;
505
506 tegra_dsi_writel(dsi, hsw << 16 | 0, DSI_PKT_LEN_0_1);
507 tegra_dsi_writel(dsi, hact << 16 | hbp, DSI_PKT_LEN_2_3);
508 tegra_dsi_writel(dsi, hfp, DSI_PKT_LEN_4_5);
509 tegra_dsi_writel(dsi, 0x0f0f << 16, DSI_PKT_LEN_6_7);
510
Thierry Reding563eff12014-11-13 14:44:27 +0100511 /* set SOL delay (for non-burst mode only) */
Thierry Redingdec72732013-09-03 08:45:46 +0200512 tegra_dsi_writel(dsi, 8 * mul / div, DSI_SOL_DELAY);
513
Thierry Reding563eff12014-11-13 14:44:27 +0100514 return 0;
515}
516
517static int tegra_output_dsi_enable(struct tegra_output *output)
518{
519 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
520 const struct drm_display_mode *mode = &dc->base.mode;
521 struct tegra_dsi *dsi = to_dsi(output);
522 u32 value;
523 int err;
524
525 if (dsi->enabled)
526 return 0;
527
528 err = tegra_dsi_configure(dsi, dc->pipe, mode);
529 if (err < 0)
530 return err;
531
Thierry Redingdec72732013-09-03 08:45:46 +0200532 /* enable display controller */
533 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
534 value |= DSI_ENABLE;
535 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
536
Thierry Redingdec72732013-09-03 08:45:46 +0200537 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
538 value &= ~DISP_CTRL_MODE_MASK;
539 value |= DISP_CTRL_MODE_C_DISPLAY;
540 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
541
Thierry Reding72d30282013-12-12 11:06:55 +0100542 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
543 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
544 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
545 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
546
Thierry Redingdec72732013-09-03 08:45:46 +0200547 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
548 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
549
550 /* enable DSI controller */
Thierry Reding563eff12014-11-13 14:44:27 +0100551 tegra_dsi_enable(dsi);
Thierry Redingdec72732013-09-03 08:45:46 +0200552
Thierry Reding334ae6b2014-03-14 14:15:10 +0100553 dsi->enabled = true;
554
Thierry Redingdec72732013-09-03 08:45:46 +0200555 return 0;
556}
557
Thierry Reding563eff12014-11-13 14:44:27 +0100558static int tegra_dsi_wait_idle(struct tegra_dsi *dsi, unsigned long timeout)
559{
560 u32 value;
561
562 timeout = jiffies + msecs_to_jiffies(timeout);
563
564 while (time_before(jiffies, timeout)) {
565 value = tegra_dsi_readl(dsi, DSI_STATUS);
566 if (value & DSI_STATUS_IDLE)
567 return 0;
568
569 usleep_range(1000, 2000);
570 }
571
572 return -ETIMEDOUT;
573}
574
575static void tegra_dsi_video_disable(struct tegra_dsi *dsi)
576{
577 u32 value;
578
579 value = tegra_dsi_readl(dsi, DSI_CONTROL);
580 value &= ~DSI_CONTROL_VIDEO_ENABLE;
581 tegra_dsi_writel(dsi, value, DSI_CONTROL);
582}
583
584static void tegra_dsi_disable(struct tegra_dsi *dsi)
585{
586 u32 value;
587
588 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
589 value &= ~DSI_POWER_CONTROL_ENABLE;
590 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
591
592 usleep_range(5000, 10000);
593}
594
Thierry Redingdec72732013-09-03 08:45:46 +0200595static int tegra_output_dsi_disable(struct tegra_output *output)
596{
597 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
598 struct tegra_dsi *dsi = to_dsi(output);
599 unsigned long value;
Thierry Reding563eff12014-11-13 14:44:27 +0100600 int err;
Thierry Redingdec72732013-09-03 08:45:46 +0200601
Thierry Reding334ae6b2014-03-14 14:15:10 +0100602 if (!dsi->enabled)
603 return 0;
604
Thierry Reding563eff12014-11-13 14:44:27 +0100605 tegra_dsi_video_disable(dsi);
Thierry Redingdec72732013-09-03 08:45:46 +0200606
607 /*
Thierry Reding72d30282013-12-12 11:06:55 +0100608 * The following accesses registers of the display controller, so make
609 * sure it's only executed when the output is attached to one.
Thierry Redingdec72732013-09-03 08:45:46 +0200610 */
611 if (dc) {
Thierry Reding72d30282013-12-12 11:06:55 +0100612 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
613 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
614 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
615 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
616
Thierry Redingdec72732013-09-03 08:45:46 +0200617 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
618 value &= ~DISP_CTRL_MODE_MASK;
619 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
620
621 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
622 value &= ~DSI_ENABLE;
623 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Reding72d30282013-12-12 11:06:55 +0100624
625 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
626 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
Thierry Redingdec72732013-09-03 08:45:46 +0200627 }
628
Thierry Reding563eff12014-11-13 14:44:27 +0100629 err = tegra_dsi_wait_idle(dsi, 100);
630 if (err < 0)
631 dev_dbg(dsi->dev, "failed to idle DSI: %d\n", err);
632
633 tegra_dsi_disable(dsi);
634
Thierry Reding334ae6b2014-03-14 14:15:10 +0100635 dsi->enabled = false;
636
Thierry Redingdec72732013-09-03 08:45:46 +0200637 return 0;
638}
639
640static int tegra_output_dsi_setup_clock(struct tegra_output *output,
Thierry Reding91eded92014-03-26 13:32:21 +0100641 struct clk *clk, unsigned long pclk,
642 unsigned int *divp)
Thierry Redingdec72732013-09-03 08:45:46 +0200643{
644 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
645 struct drm_display_mode *mode = &dc->base.mode;
646 unsigned int timeout, mul, div, vrefresh;
647 struct tegra_dsi *dsi = to_dsi(output);
648 unsigned long bclk, plld, value;
Thierry Redingdec72732013-09-03 08:45:46 +0200649 int err;
650
651 err = tegra_dsi_get_muldiv(dsi->format, &mul, &div);
652 if (err < 0)
653 return err;
654
Thierry Reding91eded92014-03-26 13:32:21 +0100655 DRM_DEBUG_KMS("mul: %u, div: %u, lanes: %u\n", mul, div, dsi->lanes);
Thierry Redingdec72732013-09-03 08:45:46 +0200656 vrefresh = drm_mode_vrefresh(mode);
Thierry Reding91eded92014-03-26 13:32:21 +0100657 DRM_DEBUG_KMS("vrefresh: %u\n", vrefresh);
Thierry Redingdec72732013-09-03 08:45:46 +0200658
Thierry Reding91eded92014-03-26 13:32:21 +0100659 /* compute byte clock */
Thierry Redingdec72732013-09-03 08:45:46 +0200660 bclk = (pclk * mul) / (div * dsi->lanes);
Thierry Reding91eded92014-03-26 13:32:21 +0100661
662 /*
663 * Compute bit clock and round up to the next MHz.
664 */
665 plld = DIV_ROUND_UP(bclk * 8, 1000000) * 1000000;
666
667 /*
668 * We divide the frequency by two here, but we make up for that by
669 * setting the shift clock divider (further below) to half of the
670 * correct value.
671 */
672 plld /= 2;
Thierry Redingdec72732013-09-03 08:45:46 +0200673
674 err = clk_set_parent(clk, dsi->clk_parent);
675 if (err < 0) {
676 dev_err(dsi->dev, "failed to set parent clock: %d\n", err);
677 return err;
678 }
679
Thierry Reding91eded92014-03-26 13:32:21 +0100680 err = clk_set_rate(dsi->clk_parent, plld);
Thierry Redingdec72732013-09-03 08:45:46 +0200681 if (err < 0) {
682 dev_err(dsi->dev, "failed to set base clock rate to %lu Hz\n",
Thierry Reding91eded92014-03-26 13:32:21 +0100683 plld);
Thierry Redingdec72732013-09-03 08:45:46 +0200684 return err;
685 }
686
687 /*
Thierry Reding91eded92014-03-26 13:32:21 +0100688 * Derive pixel clock from bit clock using the shift clock divider.
689 * Note that this is only half of what we would expect, but we need
690 * that to make up for the fact that we divided the bit clock by a
691 * factor of two above.
692 *
693 * It's not clear exactly why this is necessary, but the display is
694 * not working properly otherwise. Perhaps the PLLs cannot generate
695 * frequencies sufficiently high.
696 */
697 *divp = ((8 * mul) / (div * dsi->lanes)) - 2;
698
699 /*
Thierry Redingdec72732013-09-03 08:45:46 +0200700 * XXX: Move the below somewhere else so that we don't need to have
701 * access to the vrefresh in this function?
702 */
703
704 /* one frame high-speed transmission timeout */
705 timeout = (bclk / vrefresh) / 512;
706 value = DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout);
707 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_0);
708
709 /* 2 ms peripheral timeout for panel */
710 timeout = 2 * bclk / 512 * 1000;
711 value = DSI_TIMEOUT_PR(timeout) | DSI_TIMEOUT_TA(0x2000);
712 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_1);
713
714 value = DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
715 tegra_dsi_writel(dsi, value, DSI_TO_TALLY);
716
717 return 0;
718}
719
720static int tegra_output_dsi_check_mode(struct tegra_output *output,
721 struct drm_display_mode *mode,
722 enum drm_mode_status *status)
723{
724 /*
725 * FIXME: For now, always assume that the mode is okay.
726 */
727
728 *status = MODE_OK;
729
730 return 0;
731}
732
733static const struct tegra_output_ops dsi_ops = {
734 .enable = tegra_output_dsi_enable,
735 .disable = tegra_output_dsi_disable,
736 .setup_clock = tegra_output_dsi_setup_clock,
737 .check_mode = tegra_output_dsi_check_mode,
738};
739
740static int tegra_dsi_pad_enable(struct tegra_dsi *dsi)
741{
742 unsigned long value;
743
744 value = DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
745 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_0);
746
747 return 0;
748}
749
750static int tegra_dsi_pad_calibrate(struct tegra_dsi *dsi)
751{
Thierry Reding183ef282014-11-13 14:27:29 +0100752 u32 value;
Thierry Redingdec72732013-09-03 08:45:46 +0200753
754 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_0);
755 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_1);
756 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_2);
757 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_3);
758 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_4);
759
760 /* start calibration */
761 tegra_dsi_pad_enable(dsi);
762
763 value = DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
764 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
765 DSI_PAD_OUT_CLK(0x0);
766 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_2);
767
768 return tegra_mipi_calibrate(dsi->mipi);
769}
770
771static int tegra_dsi_init(struct host1x_client *client)
772{
Thierry Reding9910f5c2014-05-22 09:57:15 +0200773 struct drm_device *drm = dev_get_drvdata(client->parent);
Thierry Redingdec72732013-09-03 08:45:46 +0200774 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
Thierry Redingdec72732013-09-03 08:45:46 +0200775 int err;
776
777 dsi->output.type = TEGRA_OUTPUT_DSI;
778 dsi->output.dev = client->dev;
779 dsi->output.ops = &dsi_ops;
780
Thierry Reding9910f5c2014-05-22 09:57:15 +0200781 err = tegra_output_init(drm, &dsi->output);
Thierry Redingdec72732013-09-03 08:45:46 +0200782 if (err < 0) {
783 dev_err(client->dev, "output setup failed: %d\n", err);
784 return err;
785 }
786
787 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding9910f5c2014-05-22 09:57:15 +0200788 err = tegra_dsi_debugfs_init(dsi, drm->primary);
Thierry Redingdec72732013-09-03 08:45:46 +0200789 if (err < 0)
790 dev_err(dsi->dev, "debugfs setup failed: %d\n", err);
791 }
792
Thierry Redingdec72732013-09-03 08:45:46 +0200793 return 0;
794}
795
796static int tegra_dsi_exit(struct host1x_client *client)
797{
798 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
799 int err;
800
801 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
802 err = tegra_dsi_debugfs_exit(dsi);
803 if (err < 0)
804 dev_err(dsi->dev, "debugfs cleanup failed: %d\n", err);
805 }
806
807 err = tegra_output_disable(&dsi->output);
808 if (err < 0) {
809 dev_err(client->dev, "output failed to disable: %d\n", err);
810 return err;
811 }
812
813 err = tegra_output_exit(&dsi->output);
814 if (err < 0) {
815 dev_err(client->dev, "output cleanup failed: %d\n", err);
816 return err;
817 }
818
819 return 0;
820}
821
822static const struct host1x_client_ops dsi_client_ops = {
823 .init = tegra_dsi_init,
824 .exit = tegra_dsi_exit,
825};
826
827static int tegra_dsi_setup_clocks(struct tegra_dsi *dsi)
828{
829 struct clk *parent;
830 int err;
831
832 parent = clk_get_parent(dsi->clk);
833 if (!parent)
834 return -EINVAL;
835
836 err = clk_set_parent(parent, dsi->clk_parent);
837 if (err < 0)
838 return err;
839
840 return 0;
841}
842
Thierry Redingdec72732013-09-03 08:45:46 +0200843static int tegra_dsi_host_attach(struct mipi_dsi_host *host,
844 struct mipi_dsi_device *device)
845{
846 struct tegra_dsi *dsi = host_to_tegra(host);
847 struct tegra_output *output = &dsi->output;
848
Thierry Reding17297a22014-03-14 14:13:15 +0100849 dsi->flags = device->mode_flags;
Thierry Redingdec72732013-09-03 08:45:46 +0200850 dsi->format = device->format;
851 dsi->lanes = device->lanes;
852
853 output->panel = of_drm_find_panel(device->dev.of_node);
854 if (output->panel) {
855 if (output->connector.dev)
856 drm_helper_hpd_irq_event(output->connector.dev);
857 }
858
859 return 0;
860}
861
862static int tegra_dsi_host_detach(struct mipi_dsi_host *host,
863 struct mipi_dsi_device *device)
864{
865 struct tegra_dsi *dsi = host_to_tegra(host);
866 struct tegra_output *output = &dsi->output;
867
868 if (output->panel && &device->dev == output->panel->dev) {
Thierry Redingba3df972014-11-13 14:54:01 +0100869 output->panel = NULL;
870
Thierry Redingdec72732013-09-03 08:45:46 +0200871 if (output->connector.dev)
872 drm_helper_hpd_irq_event(output->connector.dev);
Thierry Redingdec72732013-09-03 08:45:46 +0200873 }
874
875 return 0;
876}
877
878static const struct mipi_dsi_host_ops tegra_dsi_host_ops = {
879 .attach = tegra_dsi_host_attach,
880 .detach = tegra_dsi_host_detach,
881};
882
883static int tegra_dsi_probe(struct platform_device *pdev)
884{
885 struct tegra_dsi *dsi;
886 struct resource *regs;
887 int err;
888
889 dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL);
890 if (!dsi)
891 return -ENOMEM;
892
893 dsi->output.dev = dsi->dev = &pdev->dev;
Thierry Reding976cebc2014-08-06 09:14:28 +0200894 dsi->video_fifo_depth = 1920;
895 dsi->host_fifo_depth = 64;
Thierry Redingdec72732013-09-03 08:45:46 +0200896
897 err = tegra_output_probe(&dsi->output);
898 if (err < 0)
899 return err;
900
Thierry Redingba3df972014-11-13 14:54:01 +0100901 dsi->output.connector.polled = DRM_CONNECTOR_POLL_HPD;
902
Thierry Redingdec72732013-09-03 08:45:46 +0200903 /*
904 * Assume these values by default. When a DSI peripheral driver
905 * attaches to the DSI host, the parameters will be taken from
906 * the attached device.
907 */
Thierry Reding17297a22014-03-14 14:13:15 +0100908 dsi->flags = MIPI_DSI_MODE_VIDEO;
Thierry Redingdec72732013-09-03 08:45:46 +0200909 dsi->format = MIPI_DSI_FMT_RGB888;
910 dsi->lanes = 4;
911
912 dsi->rst = devm_reset_control_get(&pdev->dev, "dsi");
913 if (IS_ERR(dsi->rst))
914 return PTR_ERR(dsi->rst);
915
Thierry Reding183ef282014-11-13 14:27:29 +0100916 err = reset_control_deassert(dsi->rst);
917 if (err < 0) {
918 dev_err(&pdev->dev, "failed to bring DSI out of reset: %d\n",
919 err);
920 return err;
921 }
922
Thierry Redingdec72732013-09-03 08:45:46 +0200923 dsi->clk = devm_clk_get(&pdev->dev, NULL);
924 if (IS_ERR(dsi->clk)) {
925 dev_err(&pdev->dev, "cannot get DSI clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100926 err = PTR_ERR(dsi->clk);
927 goto reset;
Thierry Redingdec72732013-09-03 08:45:46 +0200928 }
929
930 err = clk_prepare_enable(dsi->clk);
931 if (err < 0) {
932 dev_err(&pdev->dev, "cannot enable DSI clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100933 goto reset;
Thierry Redingdec72732013-09-03 08:45:46 +0200934 }
935
936 dsi->clk_lp = devm_clk_get(&pdev->dev, "lp");
937 if (IS_ERR(dsi->clk_lp)) {
938 dev_err(&pdev->dev, "cannot get low-power clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100939 err = PTR_ERR(dsi->clk_lp);
940 goto disable_clk;
Thierry Redingdec72732013-09-03 08:45:46 +0200941 }
942
943 err = clk_prepare_enable(dsi->clk_lp);
944 if (err < 0) {
945 dev_err(&pdev->dev, "cannot enable low-power clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100946 goto disable_clk;
Thierry Redingdec72732013-09-03 08:45:46 +0200947 }
948
949 dsi->clk_parent = devm_clk_get(&pdev->dev, "parent");
950 if (IS_ERR(dsi->clk_parent)) {
951 dev_err(&pdev->dev, "cannot get parent clock\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100952 err = PTR_ERR(dsi->clk_parent);
953 goto disable_clk_lp;
Thierry Redingdec72732013-09-03 08:45:46 +0200954 }
955
Thierry Reding3b077af2014-03-14 14:07:50 +0100956 dsi->vdd = devm_regulator_get(&pdev->dev, "avdd-dsi-csi");
957 if (IS_ERR(dsi->vdd)) {
958 dev_err(&pdev->dev, "cannot get VDD supply\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100959 err = PTR_ERR(dsi->vdd);
960 goto disable_clk_lp;
Thierry Reding3b077af2014-03-14 14:07:50 +0100961 }
962
963 err = regulator_enable(dsi->vdd);
964 if (err < 0) {
965 dev_err(&pdev->dev, "cannot enable VDD supply\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100966 goto disable_clk_lp;
Thierry Reding3b077af2014-03-14 14:07:50 +0100967 }
968
Thierry Redingdec72732013-09-03 08:45:46 +0200969 err = tegra_dsi_setup_clocks(dsi);
970 if (err < 0) {
971 dev_err(&pdev->dev, "cannot setup clocks\n");
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100972 goto disable_vdd;
Thierry Redingdec72732013-09-03 08:45:46 +0200973 }
974
975 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
976 dsi->regs = devm_ioremap_resource(&pdev->dev, regs);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100977 if (IS_ERR(dsi->regs)) {
978 err = PTR_ERR(dsi->regs);
979 goto disable_vdd;
980 }
Thierry Redingdec72732013-09-03 08:45:46 +0200981
Thierry Redingdec72732013-09-03 08:45:46 +0200982 dsi->mipi = tegra_mipi_request(&pdev->dev);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100983 if (IS_ERR(dsi->mipi)) {
984 err = PTR_ERR(dsi->mipi);
985 goto disable_vdd;
986 }
Thierry Redingdec72732013-09-03 08:45:46 +0200987
Thierry Reding183ef282014-11-13 14:27:29 +0100988 err = tegra_dsi_pad_calibrate(dsi);
989 if (err < 0) {
990 dev_err(dsi->dev, "MIPI calibration failed: %d\n", err);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +0100991 goto mipi_free;
Thierry Reding183ef282014-11-13 14:27:29 +0100992 }
993
Thierry Redingdec72732013-09-03 08:45:46 +0200994 dsi->host.ops = &tegra_dsi_host_ops;
995 dsi->host.dev = &pdev->dev;
996
997 err = mipi_dsi_host_register(&dsi->host);
998 if (err < 0) {
999 dev_err(&pdev->dev, "failed to register DSI host: %d\n", err);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001000 goto mipi_free;
Thierry Redingdec72732013-09-03 08:45:46 +02001001 }
1002
1003 INIT_LIST_HEAD(&dsi->client.list);
1004 dsi->client.ops = &dsi_client_ops;
1005 dsi->client.dev = &pdev->dev;
1006
1007 err = host1x_client_register(&dsi->client);
1008 if (err < 0) {
1009 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1010 err);
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001011 goto unregister;
Thierry Redingdec72732013-09-03 08:45:46 +02001012 }
1013
1014 platform_set_drvdata(pdev, dsi);
1015
1016 return 0;
Thierry Redingd2d0a9d2014-11-13 14:58:27 +01001017
1018unregister:
1019 mipi_dsi_host_unregister(&dsi->host);
1020mipi_free:
1021 tegra_mipi_free(dsi->mipi);
1022disable_vdd:
1023 regulator_disable(dsi->vdd);
1024disable_clk_lp:
1025 clk_disable_unprepare(dsi->clk_lp);
1026disable_clk:
1027 clk_disable_unprepare(dsi->clk);
1028reset:
1029 reset_control_assert(dsi->rst);
1030 return err;
Thierry Redingdec72732013-09-03 08:45:46 +02001031}
1032
1033static int tegra_dsi_remove(struct platform_device *pdev)
1034{
1035 struct tegra_dsi *dsi = platform_get_drvdata(pdev);
1036 int err;
1037
1038 err = host1x_client_unregister(&dsi->client);
1039 if (err < 0) {
1040 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1041 err);
1042 return err;
1043 }
1044
1045 mipi_dsi_host_unregister(&dsi->host);
1046 tegra_mipi_free(dsi->mipi);
1047
Thierry Reding3b077af2014-03-14 14:07:50 +01001048 regulator_disable(dsi->vdd);
Thierry Redingdec72732013-09-03 08:45:46 +02001049 clk_disable_unprepare(dsi->clk_lp);
1050 clk_disable_unprepare(dsi->clk);
Thierry Redingcb825d82014-03-14 14:25:43 +01001051 reset_control_assert(dsi->rst);
Thierry Redingdec72732013-09-03 08:45:46 +02001052
1053 err = tegra_output_remove(&dsi->output);
1054 if (err < 0) {
1055 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1056 return err;
1057 }
1058
1059 return 0;
1060}
1061
1062static const struct of_device_id tegra_dsi_of_match[] = {
1063 { .compatible = "nvidia,tegra114-dsi", },
1064 { },
1065};
Stephen Warrenef707282014-06-18 16:21:55 -06001066MODULE_DEVICE_TABLE(of, tegra_dsi_of_match);
Thierry Redingdec72732013-09-03 08:45:46 +02001067
1068struct platform_driver tegra_dsi_driver = {
1069 .driver = {
1070 .name = "tegra-dsi",
1071 .of_match_table = tegra_dsi_of_match,
1072 },
1073 .probe = tegra_dsi_probe,
1074 .remove = tegra_dsi_remove,
1075};