/
xlnx_pl_disp.c
696 lines (604 loc) · 20.2 KB
/
xlnx_pl_disp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
// SPDX-License-Identifier: GPL-2.0
/*
* Xilinx DRM CRTC DMA engine driver
*
* Copyright (C) 2017 - 2018 Xilinx, Inc.
*
* Author : Saurabh Sengar <saurabhs@xilinx.com>
* : Hyun Woo Kwon <hyun.kwon@xilinx.com>
*/
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_crtc.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_dma_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h>
#include <drm/drm_gem_dma_helper.h>
#include <drm/drm_vblank.h>
#include <linux/component.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dmaengine.h>
#include <linux/dma/xilinx_frmbuf.h>
#include <linux/of.h>
#include <linux/of_dma.h>
#include <linux/platform_device.h>
#include <video/videomode.h>
#include "xlnx_bridge.h"
#include "xlnx_crtc.h"
#include "xlnx_drv.h"
#define XLNX_PL_DISP_MAX_NUM_PLANES 3
#define XLNX_PL_DISP_VFMT_SIZE 4
/*
* Overview
* --------
*
* This driver intends to support the display pipeline with DMA engine
* driver by initializing DRM crtc and plane objects. The driver makes
* an assumption that it's single plane pipeline, as multi-plane pipeline
* would require programing beyond the DMA engine interface.
*/
/**
* struct xlnx_dma_chan - struct for DMA engine
* @dma_chan: DMA channel
* @xt: Interleaved desc config container
* @sgl: Data chunk for dma_interleaved_template
*/
struct xlnx_dma_chan {
struct dma_chan *dma_chan;
struct dma_interleaved_template xt;
struct data_chunk sgl[1];
};
/**
* struct xlnx_pl_disp - struct for display subsystem
* @dev: device structure
* @master: logical master device from xlnx drm
* @xlnx_crtc: Xilinx DRM driver crtc object
* @plane: base drm plane object
* @chan: struct for DMA engine
* @event: vblank pending event
* @callback: callback for registering DMA callback function
* @callback_param: parameter for passing to DMA callback function
* @drm: core drm object
* @fmt: drm color format
* @vtc_bridge: vtc_bridge structure
* @fid: field id
* @fid_err_prop: field id error property
* @fid_err_val: field id error value
* @fid_out_prop: field id out property
* @fid_out_val: field out value
*/
struct xlnx_pl_disp {
struct device *dev;
struct platform_device *master;
struct xlnx_crtc xlnx_crtc;
struct drm_plane plane;
struct xlnx_dma_chan *chan;
struct drm_pending_vblank_event *event;
dma_async_tx_callback callback;
void *callback_param;
struct drm_device *drm;
u32 fmt;
struct xlnx_bridge *vtc_bridge;
u32 fid;
struct drm_property *fid_err_prop;
u32 fid_err_val;
struct drm_property *fid_out_prop;
u32 fid_out_val;
};
/*
* Xlnx crtc functions
*/
static inline struct xlnx_pl_disp *crtc_to_dma(struct xlnx_crtc *xlnx_crtc)
{
return container_of(xlnx_crtc, struct xlnx_pl_disp, xlnx_crtc);
}
/**
* xlnx_pl_disp_complete - vblank handler
* @param: parameter to vblank handler
*
* This function handles the vblank interrupt, and sends an event to
* CRTC object.
*/
static void xlnx_pl_disp_complete(void *param)
{
struct xlnx_pl_disp *xlnx_pl_disp = param;
struct drm_device *drm = xlnx_pl_disp->drm;
struct xlnx_dma_chan *xlnx_dma_chan = xlnx_pl_disp->chan;
int ret;
/* Get fid err flag and fid out val */
ret = xilinx_xdma_get_fid_err_flag(xlnx_dma_chan->dma_chan,
&xlnx_pl_disp->fid_err_val);
if (ret)
dev_dbg(xlnx_pl_disp->dev, "failed to get fid_err info\n");
ret = xilinx_xdma_get_fid_out(xlnx_dma_chan->dma_chan,
&xlnx_pl_disp->fid_out_val);
if (ret)
dev_dbg(xlnx_pl_disp->dev, "failed to get fid_out info\n");
drm_handle_vblank(drm, 0);
}
/**
* xlnx_pl_disp_get_format - Get the current display pipeline format
* @xlnx_crtc: xlnx crtc object
*
* Get the current format of pipeline
*
* Return: the corresponding DRM_FORMAT_XXX
*/
static uint32_t xlnx_pl_disp_get_format(struct xlnx_crtc *xlnx_crtc)
{
struct xlnx_pl_disp *xlnx_pl_disp = crtc_to_dma(xlnx_crtc);
return xlnx_pl_disp->fmt;
}
/**
* xlnx_pl_disp_get_align - Get the alignment value for pitch
* @xlnx_crtc: xlnx crtc object
*
* Get the alignment value for pitch from the plane
*
* Return: The alignment value if successful, or the error code.
*/
static unsigned int xlnx_pl_disp_get_align(struct xlnx_crtc *xlnx_crtc)
{
struct xlnx_pl_disp *xlnx_pl_disp = crtc_to_dma(xlnx_crtc);
return 1 << xlnx_pl_disp->chan->dma_chan->device->copy_align;
}
/*
* DRM plane functions
*/
static inline struct xlnx_pl_disp *plane_to_dma(struct drm_plane *plane)
{
return container_of(plane, struct xlnx_pl_disp, plane);
}
/**
* xlnx_pl_disp_plane_disable - Disables DRM plane
* @plane: DRM plane object
*
* Disable the DRM plane, by stopping the corrosponding DMA
*/
static void xlnx_pl_disp_plane_disable(struct drm_plane *plane)
{
struct xlnx_pl_disp *xlnx_pl_disp = plane_to_dma(plane);
struct xlnx_dma_chan *xlnx_dma_chan = xlnx_pl_disp->chan;
dmaengine_terminate_sync(xlnx_dma_chan->dma_chan);
}
/**
* xlnx_pl_disp_plane_enable - Enables DRM plane
* @plane: DRM plane object
*
* Enable the DRM plane, by enabling the corresponding DMA
*/
static void xlnx_pl_disp_plane_enable(struct drm_plane *plane)
{
struct xlnx_pl_disp *xlnx_pl_disp = plane_to_dma(plane);
struct dma_async_tx_descriptor *desc;
unsigned long flags;
struct xlnx_dma_chan *xlnx_dma_chan = xlnx_pl_disp->chan;
struct dma_chan *dma_chan = xlnx_dma_chan->dma_chan;
struct dma_interleaved_template *xt = &xlnx_dma_chan->xt;
flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
desc = dmaengine_prep_interleaved_dma(dma_chan, xt, flags);
if (!desc) {
dev_err(xlnx_pl_disp->dev,
"failed to prepare DMA descriptor\n");
return;
}
desc->callback = xlnx_pl_disp->callback;
desc->callback_param = xlnx_pl_disp->callback_param;
xilinx_xdma_set_earlycb(xlnx_dma_chan->dma_chan, desc, EARLY_CALLBACK);
if (plane->state->crtc->state->adjusted_mode.flags &
DRM_MODE_FLAG_INTERLACE) {
/*
* Framebuffer DMA Reader sends the first field twice, which
* causes the following fields out of order. The fid is
* reverted to restore the order
*/
if (plane->state->fb->flags == DRM_MODE_FB_ALTERNATE_TOP) {
xlnx_pl_disp->fid = 0;
} else if (plane->state->fb->flags ==
DRM_MODE_FB_ALTERNATE_BOTTOM) {
xlnx_pl_disp->fid = 1;
} else {
/*
* FIXME: for interlace mode, application may send
* dummy packets before the video field, need to set
* the fid correctly to avoid display distortion
*/
xlnx_pl_disp->fid = 0;
}
xilinx_xdma_set_fid(xlnx_dma_chan->dma_chan, desc,
xlnx_pl_disp->fid);
}
dmaengine_submit(desc);
dma_async_issue_pending(xlnx_dma_chan->dma_chan);
}
static void xlnx_pl_disp_plane_atomic_disable(struct drm_plane *plane,
struct drm_atomic_state *state)
{
xlnx_pl_disp_plane_disable(plane);
}
static int xlnx_pl_disp_plane_mode_set(struct drm_plane *plane,
struct drm_framebuffer *fb,
int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h,
u32 src_x, uint32_t src_y,
u32 src_w, uint32_t src_h)
{
struct xlnx_pl_disp *xlnx_pl_disp = plane_to_dma(plane);
const struct drm_format_info *info = fb->format;
dma_addr_t luma_paddr, chroma_paddr;
size_t stride;
struct xlnx_dma_chan *xlnx_dma_chan = xlnx_pl_disp->chan;
if (info->num_planes > XLNX_PL_DISP_MAX_NUM_PLANES) {
dev_err(xlnx_pl_disp->dev, "Color format not supported\n");
return -EINVAL;
}
luma_paddr = drm_fb_dma_get_gem_addr(fb, plane->state, 0);
if (!luma_paddr) {
dev_err(xlnx_pl_disp->dev, "failed to get luma paddr\n");
return -EINVAL;
}
dev_dbg(xlnx_pl_disp->dev, "num planes = %d\n", info->num_planes);
xlnx_dma_chan->xt.numf = src_h;
xlnx_dma_chan->sgl[0].size = drm_format_plane_width_bytes(info,
0, src_w);
xlnx_dma_chan->sgl[0].icg = fb->pitches[0] - xlnx_dma_chan->sgl[0].size;
xlnx_dma_chan->xt.src_start = luma_paddr;
xlnx_dma_chan->xt.frame_size = info->num_planes;
xlnx_dma_chan->xt.dir = DMA_MEM_TO_DEV;
xlnx_dma_chan->xt.src_sgl = true;
xlnx_dma_chan->xt.dst_sgl = false;
/* Do we have a video format aware dma channel?
* so, modify descriptor accordingly. Hueristic test:
* we have a multi-plane format but only one dma channel
*/
if (info->num_planes > 1) {
chroma_paddr = drm_fb_dma_get_gem_addr(fb, plane->state, 1);
if (!chroma_paddr) {
dev_err(xlnx_pl_disp->dev,
"failed to get chroma paddr\n");
return -EINVAL;
}
stride = xlnx_dma_chan->sgl[0].size +
xlnx_dma_chan->sgl[0].icg;
xlnx_dma_chan->sgl[0].src_icg = chroma_paddr -
xlnx_dma_chan->xt.src_start -
(xlnx_dma_chan->xt.numf * stride);
}
return 0;
}
static void xlnx_pl_disp_plane_atomic_update(struct drm_plane *plane,
struct drm_atomic_state *state)
{
int ret;
struct xlnx_pl_disp *xlnx_pl_disp = plane_to_dma(plane);
ret = xlnx_pl_disp_plane_mode_set(plane,
plane->state->fb,
plane->state->crtc_x,
plane->state->crtc_y,
plane->state->crtc_w,
plane->state->crtc_h,
plane->state->src_x >> 16,
plane->state->src_y >> 16,
plane->state->src_w >> 16,
plane->state->src_h >> 16);
if (ret) {
dev_err(xlnx_pl_disp->dev, "failed to mode set a plane\n");
return;
}
/* in case frame buffer is used set the color format */
xilinx_xdma_drm_config(xlnx_pl_disp->chan->dma_chan,
xlnx_pl_disp->plane.state->fb->format->format);
/* apply the new fb addr and enable */
xlnx_pl_disp_plane_enable(plane);
}
static int
xlnx_pl_disp_plane_atomic_check(struct drm_plane *plane,
struct drm_atomic_state *state)
{
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
const struct drm_plane_state *old_plane_state =
drm_atomic_get_old_plane_state(state, plane);
struct drm_crtc *crtc = new_plane_state->crtc ?: old_plane_state->crtc;
struct drm_crtc_state *new_crtc_state;
if (!crtc)
return 0;
new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
/* plane must be enabled when state is active */
if (new_crtc_state->active && !new_plane_state->crtc)
return -EINVAL;
/*
* This check is required to call modeset if there is a change in color
* format
*/
if (new_plane_state->fb && old_plane_state->fb &&
new_plane_state->fb->format->format !=
old_plane_state->fb->format->format)
new_crtc_state->mode_changed = true;
return 0;
}
static int
xlnx_pl_disp_plane_atomic_get_property(struct drm_plane *plane,
const struct drm_plane_state *state,
struct drm_property *property,
uint64_t *val)
{
struct xlnx_pl_disp *xlnx_pl_disp = plane_to_dma(plane);
if (property == xlnx_pl_disp->fid_err_prop)
*val = xlnx_pl_disp->fid_err_val;
else if (property == xlnx_pl_disp->fid_out_prop)
*val = xlnx_pl_disp->fid_out_val;
else
return -EINVAL;
return 0;
}
static const struct drm_plane_helper_funcs xlnx_pl_disp_plane_helper_funcs = {
.atomic_update = xlnx_pl_disp_plane_atomic_update,
.atomic_disable = xlnx_pl_disp_plane_atomic_disable,
.atomic_check = xlnx_pl_disp_plane_atomic_check,
};
static struct drm_plane_funcs xlnx_pl_disp_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
.destroy = drm_plane_cleanup,
.reset = drm_atomic_helper_plane_reset,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
.atomic_get_property = xlnx_pl_disp_plane_atomic_get_property,
};
static inline struct xlnx_pl_disp *drm_crtc_to_dma(struct drm_crtc *crtc)
{
struct xlnx_crtc *xlnx_crtc = to_xlnx_crtc(crtc);
return crtc_to_dma(xlnx_crtc);
}
static void xlnx_pl_disp_crtc_atomic_begin(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
drm_crtc_vblank_on(crtc);
spin_lock_irq(&crtc->dev->event_lock);
if (crtc->state->event) {
/* Consume the flip_done event from atomic helper */
crtc->state->event->pipe = drm_crtc_index(crtc);
WARN_ON(drm_crtc_vblank_get(crtc) != 0);
drm_crtc_arm_vblank_event(crtc, crtc->state->event);
crtc->state->event = NULL;
}
spin_unlock_irq(&crtc->dev->event_lock);
}
static void xlnx_pl_disp_clear_event(struct drm_crtc *crtc)
{
if (crtc->state->event) {
complete_all(crtc->state->event->base.completion);
crtc->state->event = NULL;
}
}
static void xlnx_pl_disp_crtc_atomic_enable(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
int vrefresh;
struct xlnx_crtc *xlnx_crtc = to_xlnx_crtc(crtc);
struct xlnx_pl_disp *xlnx_pl_disp = crtc_to_dma(xlnx_crtc);
struct videomode vm;
if (xlnx_pl_disp->vtc_bridge) {
/* set video timing */
drm_display_mode_to_videomode(adjusted_mode, &vm);
xlnx_bridge_set_timing(xlnx_pl_disp->vtc_bridge, &vm);
xlnx_bridge_enable(xlnx_pl_disp->vtc_bridge);
}
xlnx_pl_disp_plane_enable(crtc->primary);
/* Delay of 1 vblank interval for timing gen to be stable */
vrefresh = (adjusted_mode->clock * 1000) /
(adjusted_mode->vtotal * adjusted_mode->htotal);
msleep(1 * 1000 / vrefresh);
}
static void xlnx_pl_disp_crtc_atomic_disable(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
struct xlnx_crtc *xlnx_crtc = to_xlnx_crtc(crtc);
struct xlnx_pl_disp *xlnx_pl_disp = crtc_to_dma(xlnx_crtc);
xlnx_pl_disp_plane_disable(crtc->primary);
xlnx_pl_disp_clear_event(crtc);
drm_crtc_vblank_off(crtc);
if (xlnx_pl_disp->vtc_bridge)
xlnx_bridge_disable(xlnx_pl_disp->vtc_bridge);
}
static int xlnx_pl_disp_crtc_atomic_check(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
return drm_atomic_add_affected_planes(state, crtc);
}
static struct drm_crtc_helper_funcs xlnx_pl_disp_crtc_helper_funcs = {
.atomic_enable = xlnx_pl_disp_crtc_atomic_enable,
.atomic_disable = xlnx_pl_disp_crtc_atomic_disable,
.atomic_check = xlnx_pl_disp_crtc_atomic_check,
.atomic_begin = xlnx_pl_disp_crtc_atomic_begin,
};
static void xlnx_pl_disp_crtc_destroy(struct drm_crtc *crtc)
{
xlnx_pl_disp_plane_disable(crtc->primary);
drm_crtc_cleanup(crtc);
}
static int xlnx_pl_disp_crtc_enable_vblank(struct drm_crtc *crtc)
{
struct xlnx_crtc *xlnx_crtc = to_xlnx_crtc(crtc);
struct xlnx_pl_disp *xlnx_pl_disp = crtc_to_dma(xlnx_crtc);
/*
* Use the complete callback for vblank event assuming the dma engine
* starts on the next descriptor upon this event. This may not be safe
* assumption for some dma engines.
*/
xlnx_pl_disp->callback = xlnx_pl_disp_complete;
xlnx_pl_disp->callback_param = xlnx_pl_disp;
return 0;
}
static void xlnx_pl_disp_crtc_disable_vblank(struct drm_crtc *crtc)
{
struct xlnx_crtc *xlnx_crtc = to_xlnx_crtc(crtc);
struct xlnx_pl_disp *xlnx_pl_disp = crtc_to_dma(xlnx_crtc);
xlnx_pl_disp->callback = NULL;
xlnx_pl_disp->callback_param = NULL;
}
static struct drm_crtc_funcs xlnx_pl_disp_crtc_funcs = {
.destroy = xlnx_pl_disp_crtc_destroy,
.set_config = drm_atomic_helper_set_config,
.page_flip = drm_atomic_helper_page_flip,
.reset = drm_atomic_helper_crtc_reset,
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
.enable_vblank = xlnx_pl_disp_crtc_enable_vblank,
.disable_vblank = xlnx_pl_disp_crtc_disable_vblank,
};
static int xlnx_pl_disp_bind(struct device *dev, struct device *master,
void *data)
{
struct drm_device *drm = data;
struct xlnx_pl_disp *xlnx_pl_disp = dev_get_drvdata(dev);
struct drm_mode_object *obj = &xlnx_pl_disp->plane.base;
int ret;
u32 *fmts = NULL;
unsigned int num_fmts = 0;
/* in case of fb IP query the supported formats and there count */
xilinx_xdma_get_drm_vid_fmts(xlnx_pl_disp->chan->dma_chan,
&num_fmts, &fmts);
ret = drm_universal_plane_init(drm, &xlnx_pl_disp->plane, 0,
&xlnx_pl_disp_plane_funcs,
fmts ? fmts : &xlnx_pl_disp->fmt,
num_fmts ? num_fmts : 1,
NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
if (ret)
return ret;
drm_plane_helper_add(&xlnx_pl_disp->plane,
&xlnx_pl_disp_plane_helper_funcs);
ret = drm_crtc_init_with_planes(drm, &xlnx_pl_disp->xlnx_crtc.crtc,
&xlnx_pl_disp->plane, NULL,
&xlnx_pl_disp_crtc_funcs, NULL);
if (ret) {
drm_plane_cleanup(&xlnx_pl_disp->plane);
return ret;
}
drm_crtc_helper_add(&xlnx_pl_disp->xlnx_crtc.crtc,
&xlnx_pl_disp_crtc_helper_funcs);
xlnx_pl_disp->xlnx_crtc.get_format = &xlnx_pl_disp_get_format;
xlnx_pl_disp->xlnx_crtc.get_align = &xlnx_pl_disp_get_align;
xlnx_pl_disp->drm = drm;
xlnx_pl_disp->fid_err_prop = drm_property_create_bool(xlnx_pl_disp->drm,
0, "fid_err");
xlnx_pl_disp->fid_out_prop = drm_property_create_bool(xlnx_pl_disp->drm,
0, "fid_out");
drm_object_attach_property(obj, xlnx_pl_disp->fid_err_prop, 0);
drm_object_attach_property(obj, xlnx_pl_disp->fid_out_prop, 0);
xlnx_crtc_register(xlnx_pl_disp->drm, &xlnx_pl_disp->xlnx_crtc);
return 0;
}
static void xlnx_pl_disp_unbind(struct device *dev, struct device *master,
void *data)
{
struct xlnx_pl_disp *xlnx_pl_disp = dev_get_drvdata(dev);
drm_property_destroy(xlnx_pl_disp->drm, xlnx_pl_disp->fid_out_prop);
drm_property_destroy(xlnx_pl_disp->drm, xlnx_pl_disp->fid_err_prop);
xlnx_crtc_unregister(xlnx_pl_disp->drm, &xlnx_pl_disp->xlnx_crtc);
drm_plane_cleanup(&xlnx_pl_disp->plane);
drm_crtc_cleanup(&xlnx_pl_disp->xlnx_crtc.crtc);
}
static const struct component_ops xlnx_pl_disp_component_ops = {
.bind = xlnx_pl_disp_bind,
.unbind = xlnx_pl_disp_unbind,
};
static int xlnx_pl_disp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *vtc_node;
struct xlnx_pl_disp *xlnx_pl_disp;
int ret;
const char *vformat;
struct dma_chan *dma_chan;
struct xlnx_dma_chan *xlnx_dma_chan;
const struct drm_format_info *info;
xlnx_pl_disp = devm_kzalloc(dev, sizeof(*xlnx_pl_disp), GFP_KERNEL);
if (!xlnx_pl_disp)
return -ENOMEM;
dma_chan = of_dma_request_slave_channel(dev->of_node, "dma0");
if (IS_ERR_OR_NULL(dma_chan)) {
dev_err(dev, "failed to request dma channel\n");
return PTR_ERR(dma_chan);
}
xlnx_dma_chan = devm_kzalloc(dev, sizeof(*xlnx_dma_chan), GFP_KERNEL);
if (!xlnx_dma_chan)
return -ENOMEM;
xlnx_dma_chan->dma_chan = dma_chan;
xlnx_pl_disp->chan = xlnx_dma_chan;
ret = of_property_read_string(dev->of_node, "xlnx,vformat", &vformat);
if (ret) {
dev_err(dev, "No xlnx,vformat value in dts\n");
goto err_dma;
}
strncpy((char *)&xlnx_pl_disp->fmt, vformat, XLNX_PL_DISP_VFMT_SIZE);
info = drm_format_info(xlnx_pl_disp->fmt);
if (!info) {
dev_err(dev, "Invalid video format in dts\n");
ret = -EINVAL;
goto err_dma;
}
/* VTC Bridge support */
vtc_node = of_parse_phandle(dev->of_node, "xlnx,bridge", 0);
if (vtc_node) {
xlnx_pl_disp->vtc_bridge = of_xlnx_bridge_get(vtc_node);
if (!xlnx_pl_disp->vtc_bridge) {
dev_info(dev, "Didn't get vtc bridge instance\n");
ret = -EPROBE_DEFER;
goto err_dma;
}
} else {
dev_info(dev, "vtc bridge property not present\n");
}
xlnx_pl_disp->dev = dev;
platform_set_drvdata(pdev, xlnx_pl_disp);
ret = component_add(dev, &xlnx_pl_disp_component_ops);
if (ret)
goto err_dma;
xlnx_pl_disp->master = xlnx_drm_pipeline_init(pdev);
if (IS_ERR(xlnx_pl_disp->master)) {
ret = PTR_ERR(xlnx_pl_disp->master);
dev_err(dev, "failed to initialize the drm pipeline\n");
goto err_component;
}
dev_info(&pdev->dev, "Xlnx PL display driver probed\n");
return 0;
err_component:
component_del(dev, &xlnx_pl_disp_component_ops);
err_dma:
dma_release_channel(xlnx_pl_disp->chan->dma_chan);
return ret;
}
static int xlnx_pl_disp_remove(struct platform_device *pdev)
{
struct xlnx_pl_disp *xlnx_pl_disp = platform_get_drvdata(pdev);
struct xlnx_dma_chan *xlnx_dma_chan = xlnx_pl_disp->chan;
if (xlnx_pl_disp->vtc_bridge)
of_xlnx_bridge_put(xlnx_pl_disp->vtc_bridge);
xlnx_drm_pipeline_exit(xlnx_pl_disp->master);
component_del(&pdev->dev, &xlnx_pl_disp_component_ops);
/* Make sure the channel is terminated before release */
dmaengine_terminate_sync(xlnx_dma_chan->dma_chan);
dma_release_channel(xlnx_dma_chan->dma_chan);
return 0;
}
static const struct of_device_id xlnx_pl_disp_of_match[] = {
{ .compatible = "xlnx,pl-disp"},
{ }
};
MODULE_DEVICE_TABLE(of, xlnx_pl_disp_of_match);
static struct platform_driver xlnx_pl_disp_driver = {
.probe = xlnx_pl_disp_probe,
.remove = xlnx_pl_disp_remove,
.driver = {
.name = "xlnx-pl-disp",
.of_match_table = xlnx_pl_disp_of_match,
},
};
module_platform_driver(xlnx_pl_disp_driver);
MODULE_AUTHOR("Saurabh Sengar");
MODULE_DESCRIPTION("Xilinx DRM Display Driver for PL IPs");
MODULE_LICENSE("GPL");