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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
|
/* Copyright (c) 2015-2020, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define pr_fmt(fmt) "[drm-shd:%s:%d] " fmt, __func__, __LINE__
#include <linux/debugfs.h>
#include <uapi/drm/sde_drm.h>
#include "sde_encoder_phys.h"
#include "sde_formats.h"
#include "sde_hw_top.h"
#include "sde_hw_interrupts.h"
#include "sde_core_irq.h"
#include "sde_crtc.h"
#include "sde_trace.h"
#include "sde_plane.h"
#include "shd_drm.h"
#include "shd_hw.h"
#define SDE_ERROR_PHYS(p, fmt, ...) SDE_ERROR("enc%d intf%d " fmt,\
(p) ? (p)->parent->base.id : -1, \
(p) ? (p)->intf_idx - INTF_0 : -1, \
##__VA_ARGS__)
#define SDE_DEBUG_PHYS(p, fmt, ...) SDE_DEBUG("enc%d intf%d " fmt,\
(p) ? (p)->parent->base.id : -1, \
(p) ? (p)->intf_idx - INTF_0 : -1, \
##__VA_ARGS__)
/**
* struct sde_encoder_phys_shd - sub-class of sde_encoder_phys to handle shared
* mode specific operations
* @base: Baseclass physical encoder structure
* @hw_lm: HW LM blocks created by this shared encoder
* @hw_ctl: HW CTL blocks created by this shared encoder
* @num_mixers: Number of LM blocks
* @num_ctls: Number of CTL blocks
*/
struct sde_encoder_phys_shd {
struct sde_encoder_phys base;
struct sde_hw_mixer *hw_lm[CRTC_DUAL_MIXERS];
struct sde_hw_ctl *hw_ctl[CRTC_DUAL_MIXERS];
u32 num_mixers;
u32 num_ctls;
};
#define to_sde_encoder_phys_shd(x) \
container_of(x, struct sde_encoder_phys_shd, base)
static inline
bool sde_encoder_phys_shd_is_master(struct sde_encoder_phys *phys_enc)
{
return true;
}
static void sde_encoder_phys_shd_vblank_irq(void *arg, int irq_idx)
{
struct sde_encoder_phys *phys_enc = arg;
struct sde_hw_ctl *hw_ctl;
struct sde_shd_hw_ctl *shd_ctl;
unsigned long lock_flags;
u32 flush_register = ~0;
int new_cnt = -1, old_cnt = -1;
u32 event = 0;
if (!phys_enc)
return;
hw_ctl = phys_enc->hw_ctl;
if (!hw_ctl)
return;
SDE_ATRACE_BEGIN("vblank_irq");
/*
* only decrement the pending flush count if we've actually flushed
* hardware. due to sw irq latency, vblank may have already happened
* so we need to double-check with hw that it accepted the flush bits
*/
spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
old_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
if (hw_ctl && hw_ctl->ops.get_flush_register)
flush_register = hw_ctl->ops.get_flush_register(hw_ctl);
shd_ctl = container_of(hw_ctl, struct sde_shd_hw_ctl, base);
if (flush_register)
SDE_DEBUG("%d irq flush=0x%x mask=0x%x\n",
DRMID(phys_enc->parent),
flush_register, shd_ctl->flush_mask);
if (flush_register & shd_ctl->flush_mask)
goto not_flushed;
/*
* When flush_mask is changed to 0, we need additional vsync
* to make sure the detach flush is done
*/
if (flush_register && !shd_ctl->flush_mask && shd_ctl->old_mask) {
shd_ctl->old_mask = 0;
goto not_flushed;
}
new_cnt = atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0);
if (atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0))
event |= SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE |
SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
not_flushed:
spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
if (event && phys_enc->parent_ops.handle_frame_done)
phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
phys_enc, event);
if (phys_enc->parent_ops.handle_vblank_virt)
phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
phys_enc);
SDE_EVT32_IRQ(DRMID(phys_enc->parent), phys_enc->hw_intf->idx - INTF_0,
old_cnt, new_cnt,
flush_register, event);
/* Signal any waiting atomic commit thread */
wake_up_all(&phys_enc->pending_kickoff_wq);
SDE_ATRACE_END("vblank_irq");
}
static int _sde_encoder_phys_shd_register_irq(
struct sde_encoder_phys *phys_enc,
enum sde_intr_idx intr_idx,
bool enable)
{
SDE_DEBUG("%d enable %d\n", DRMID(phys_enc->parent), enable);
if (enable)
return sde_encoder_helper_register_irq(phys_enc,
INTR_IDX_VSYNC);
else
return sde_encoder_helper_unregister_irq(phys_enc,
INTR_IDX_VSYNC);
}
static inline
void _sde_encoder_phys_shd_setup_irq_hw_idx(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_irq *irq;
irq = &phys_enc->irq[INTR_IDX_VSYNC];
if (irq->irq_idx < 0)
irq->hw_idx = phys_enc->intf_idx;
}
static int _sde_encoder_phys_shd_rm_reserve(
struct sde_encoder_phys *phys_enc,
struct shd_display *display)
{
struct sde_encoder_phys_shd *shd_enc;
struct sde_rm *rm;
struct sde_rm_hw_iter ctl_iter, lm_iter, pp_iter;
struct drm_encoder *encoder;
struct sde_shd_hw_ctl *hw_ctl;
struct sde_shd_hw_mixer *hw_lm;
struct sde_hw_pingpong *hw_pp;
int i, rc = 0;
encoder = display->base->encoder;
rm = &phys_enc->sde_kms->rm;
shd_enc = to_sde_encoder_phys_shd(phys_enc);
sde_rm_init_hw_iter(&ctl_iter, encoder->base.id, SDE_HW_BLK_CTL);
sde_rm_init_hw_iter(&lm_iter, encoder->base.id, SDE_HW_BLK_LM);
sde_rm_init_hw_iter(&pp_iter, encoder->base.id, SDE_HW_BLK_PINGPONG);
shd_enc->num_mixers = 0;
shd_enc->num_ctls = 0;
for (i = 0; i < CRTC_DUAL_MIXERS; i++) {
/* reserve lm */
if (!sde_rm_get_hw(rm, &lm_iter))
break;
hw_lm = container_of(shd_enc->hw_lm[i],
struct sde_shd_hw_mixer, base);
hw_lm->base = *(struct sde_hw_mixer *)lm_iter.hw;
hw_lm->range = display->stage_range;
hw_lm->roi = display->roi;
hw_lm->orig = lm_iter.hw;
sde_shd_hw_lm_init_op(&hw_lm->base);
SDE_DEBUG("reserve LM%d %pK from enc %d to %d\n",
hw_lm->base.idx, hw_lm,
DRMID(encoder),
DRMID(phys_enc->parent));
rc = sde_rm_ext_blk_create_reserve(rm,
&hw_lm->base.base, phys_enc->parent);
if (rc) {
SDE_ERROR("failed to create & reserve lm\n");
break;
}
shd_enc->num_mixers++;
/* reserve ctl */
if (!sde_rm_get_hw(rm, &ctl_iter))
break;
hw_ctl = container_of(shd_enc->hw_ctl[i],
struct sde_shd_hw_ctl, base);
hw_ctl->base = *(struct sde_hw_ctl *)ctl_iter.hw;
hw_ctl->range = display->stage_range;
hw_ctl->orig = ctl_iter.hw;
sde_shd_hw_ctl_init_op(&hw_ctl->base);
SDE_DEBUG("reserve CTL%d %pK from enc %d to %d\n",
hw_ctl->base.idx, hw_ctl,
DRMID(encoder),
DRMID(phys_enc->parent));
rc = sde_rm_ext_blk_create_reserve(rm,
&hw_ctl->base.base, phys_enc->parent);
if (rc) {
SDE_ERROR("failed to create & reserve ctl\n");
break;
}
shd_enc->num_ctls++;
/* reserve pingpong */
if (!sde_rm_get_hw(rm, &pp_iter))
break;
hw_pp = pp_iter.hw;
SDE_DEBUG("reserve PP%d from enc %d to %d\n",
hw_pp->idx,
DRMID(encoder),
DRMID(phys_enc->parent));
rc = sde_rm_ext_blk_create_reserve(rm,
&hw_pp->base, phys_enc->parent);
if (rc) {
SDE_ERROR("failed to create & reserve pingpong\n");
break;
}
}
return rc;
}
static inline void _sde_encoder_phys_shd_rm_release(
struct sde_encoder_phys *phys_enc,
struct shd_display *display)
{
struct sde_rm *rm;
rm = &phys_enc->sde_kms->rm;
sde_rm_ext_blk_destroy(rm, phys_enc->parent);
}
static void sde_encoder_phys_shd_mode_set(
struct sde_encoder_phys *phys_enc,
struct drm_display_mode *mode,
struct drm_display_mode *adj_mode)
{
struct drm_connector *connector;
struct shd_display *display;
struct drm_encoder *encoder;
struct sde_rm_hw_iter iter;
struct sde_rm *rm;
SDE_DEBUG("%d\n", phys_enc->parent->base.id);
phys_enc->cached_mode = *adj_mode;
connector = phys_enc->connector;
if (!connector || connector->encoder != phys_enc->parent) {
SDE_ERROR("failed to find connector\n");
return;
}
display = sde_connector_get_display(connector);
encoder = display->base->encoder;
if (_sde_encoder_phys_shd_rm_reserve(phys_enc, display))
return;
rm = &phys_enc->sde_kms->rm;
sde_rm_init_hw_iter(&iter, DRMID(phys_enc->parent), SDE_HW_BLK_CTL);
if (sde_rm_get_hw(rm, &iter))
phys_enc->hw_ctl = (struct sde_hw_ctl *)iter.hw;
if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
SDE_DEBUG("failed to init ctl, %ld\n",
PTR_ERR(phys_enc->hw_ctl));
phys_enc->hw_ctl = NULL;
return;
}
sde_rm_init_hw_iter(&iter, DRMID(encoder), SDE_HW_BLK_INTF);
if (sde_rm_get_hw(rm, &iter))
phys_enc->hw_intf = (struct sde_hw_intf *)iter.hw;
if (IS_ERR_OR_NULL(phys_enc->hw_intf)) {
SDE_DEBUG("failed to init intf: %ld\n",
PTR_ERR(phys_enc->hw_intf));
phys_enc->hw_intf = NULL;
return;
}
sde_rm_init_hw_iter(&iter, DRMID(encoder), SDE_HW_BLK_PINGPONG);
if (sde_rm_get_hw(rm, &iter))
phys_enc->hw_pp = (struct sde_hw_pingpong *)iter.hw;
if (IS_ERR_OR_NULL(phys_enc->hw_pp)) {
SDE_DEBUG("failed to init pingpong: %ld\n",
PTR_ERR(phys_enc->hw_pp));
phys_enc->hw_pp = NULL;
return;
}
_sde_encoder_phys_shd_setup_irq_hw_idx(phys_enc);
}
static int _sde_encoder_phys_shd_wait_for_vblank(
struct sde_encoder_phys *phys_enc, bool notify)
{
struct sde_encoder_wait_info wait_info;
int ret = 0;
u32 event = 0;
u32 event_helper = 0;
if (!phys_enc) {
pr_err("invalid encoder\n");
return -EINVAL;
}
wait_info.wq = &phys_enc->pending_kickoff_wq;
wait_info.atomic_cnt = &phys_enc->pending_kickoff_cnt;
wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
/* Wait for kickoff to complete */
ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_VSYNC,
&wait_info);
event_helper = SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE
| SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE;
if (notify) {
if (ret == -ETIMEDOUT) {
event = SDE_ENCODER_FRAME_EVENT_ERROR;
if (atomic_add_unless(
&phys_enc->pending_retire_fence_cnt, -1, 0))
event |= event_helper;
} else if (!ret) {
event = SDE_ENCODER_FRAME_EVENT_DONE;
}
}
SDE_EVT32(DRMID(phys_enc->parent), event, notify, ret,
ret ? SDE_EVTLOG_FATAL : 0);
if (phys_enc->parent_ops.handle_frame_done && event)
phys_enc->parent_ops.handle_frame_done(
phys_enc->parent, phys_enc,
event);
return ret;
}
static inline
int sde_encoder_phys_shd_wait_for_vblank(
struct sde_encoder_phys *phys_enc)
{
return _sde_encoder_phys_shd_wait_for_vblank(phys_enc, true);
}
static inline
int sde_encoder_phys_shd_wait_for_vblank_no_notify(
struct sde_encoder_phys *phys_enc)
{
return _sde_encoder_phys_shd_wait_for_vblank(phys_enc, false);
}
static inline
int sde_encoder_phys_shd_prepare_for_kickoff(
struct sde_encoder_phys *phys_enc,
struct sde_encoder_kickoff_params *params)
{
return 0;
}
static inline
void sde_encoder_phys_shd_handle_post_kickoff(
struct sde_encoder_phys *phys_enc)
{
if (!phys_enc || !phys_enc->hw_intf) {
SDE_ERROR("invalid encoder\n");
return;
}
if (phys_enc->enable_state == SDE_ENC_ENABLING) {
SDE_EVT32(DRMID(phys_enc->parent),
phys_enc->hw_intf->idx - INTF_0);
phys_enc->enable_state = SDE_ENC_ENABLED;
}
}
static inline
void sde_encoder_phys_shd_trigger_flush(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_shd *shd_enc;
shd_enc = container_of(phys_enc, struct sde_encoder_phys_shd, base);
sde_shd_hw_flush(phys_enc->hw_ctl,
shd_enc->hw_lm, shd_enc->num_mixers);
}
static int sde_encoder_phys_shd_control_vblank_irq(
struct sde_encoder_phys *phys_enc,
bool enable)
{
int ret = 0;
struct sde_encoder_phys_shd *shd_enc;
int refcount;
if (!phys_enc || !phys_enc->hw_intf) {
SDE_ERROR("invalid encoder\n");
return -EINVAL;
}
refcount = atomic_read(&phys_enc->vblank_refcount);
shd_enc = to_sde_encoder_phys_shd(phys_enc);
/* protect against negative */
if (!enable && refcount == 0) {
ret = -EINVAL;
goto end;
}
SDE_DEBUG("[%pS] %d enable=%d/%d\n",
__builtin_return_address(0), DRMID(phys_enc->parent),
enable, atomic_read(&phys_enc->vblank_refcount));
SDE_EVT32(DRMID(phys_enc->parent), enable,
atomic_read(&phys_enc->vblank_refcount));
if (enable && atomic_inc_return(&phys_enc->vblank_refcount) == 1) {
ret = _sde_encoder_phys_shd_register_irq(phys_enc,
INTR_IDX_VSYNC, true);
if (ret)
atomic_dec_return(&phys_enc->vblank_refcount);
} else if (!enable &&
atomic_dec_return(&phys_enc->vblank_refcount) == 0) {
ret = _sde_encoder_phys_shd_register_irq(phys_enc,
INTR_IDX_VSYNC, false);
if (ret)
atomic_inc_return(&phys_enc->vblank_refcount);
}
end:
if (ret) {
SDE_DEBUG("control vblank irq error %d, enable %d\n",
ret, enable);
SDE_EVT32(DRMID(phys_enc->parent),
phys_enc->hw_intf->idx - INTF_0,
enable, refcount, SDE_EVTLOG_ERROR);
}
return ret;
}
static void sde_encoder_phys_shd_enable(struct sde_encoder_phys *phys_enc)
{
struct drm_connector *connector;
SDE_DEBUG("%d\n", phys_enc->parent->base.id);
if (!phys_enc->parent || !phys_enc->parent->dev) {
SDE_ERROR("invalid drm device\n");
return;
}
connector = phys_enc->connector;
if (!connector || connector->encoder != phys_enc->parent) {
SDE_ERROR("failed to find connector\n");
return;
}
if (phys_enc->enable_state == SDE_ENC_DISABLED)
phys_enc->enable_state = SDE_ENC_ENABLING;
SDE_EVT32(DRMID(phys_enc->parent),
atomic_read(&phys_enc->pending_retire_fence_cnt));
}
static void sde_encoder_phys_shd_single_vblank_wait(
struct sde_encoder_phys *phys_enc)
{
int ret;
ret = sde_encoder_phys_shd_control_vblank_irq(phys_enc, true);
if (ret) {
SDE_ERROR_PHYS(phys_enc,
"failed to enable vblank irq: %d\n",
ret);
SDE_EVT32(DRMID(phys_enc->parent),
phys_enc->hw_intf->idx - INTF_0, ret,
SDE_EVTLOG_FUNC_CASE1,
SDE_EVTLOG_ERROR);
} else {
ret = _sde_encoder_phys_shd_wait_for_vblank(phys_enc, false);
if (ret) {
atomic_set(&phys_enc->pending_kickoff_cnt, 0);
SDE_ERROR_PHYS(phys_enc,
"failure waiting for disable: %d\n",
ret);
SDE_EVT32(DRMID(phys_enc->parent),
phys_enc->hw_intf->idx - INTF_0, ret,
SDE_EVTLOG_FUNC_CASE2,
SDE_EVTLOG_ERROR);
}
sde_encoder_phys_shd_control_vblank_irq(phys_enc, false);
}
}
static void sde_encoder_phys_shd_disable(struct sde_encoder_phys *phys_enc)
{
struct shd_display *display;
unsigned long lock_flags;
SDE_DEBUG("%d\n", phys_enc->parent->base.id);
if (!phys_enc || !phys_enc->parent || !phys_enc->parent->dev ||
!phys_enc->parent->dev->dev_private) {
SDE_ERROR("invalid encoder/device\n");
return;
}
if (!phys_enc->hw_intf || !phys_enc->hw_ctl) {
SDE_ERROR("invalid hw_intf %d hw_ctl %d\n",
phys_enc->hw_intf != 0, phys_enc->hw_ctl != 0);
return;
}
if (phys_enc->enable_state == SDE_ENC_DISABLED) {
SDE_ERROR("already disabled\n");
return;
}
sde_encoder_helper_reset_mixers(phys_enc, NULL);
display = sde_connector_get_display(phys_enc->connector);
if (!display)
goto next;
/* if base display is already disabled, skip vsync check */
if (!display->base->crtc->state->active)
goto next;
spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
sde_encoder_phys_shd_trigger_flush(phys_enc);
sde_encoder_phys_inc_pending(phys_enc);
spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
sde_encoder_phys_shd_single_vblank_wait(phys_enc);
next:
phys_enc->enable_state = SDE_ENC_DISABLED;
_sde_encoder_phys_shd_rm_release(phys_enc, display);
SDE_EVT32(DRMID(phys_enc->parent),
atomic_read(&phys_enc->pending_retire_fence_cnt));
}
static inline
void sde_encoder_phys_shd_destroy(struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_shd *shd_enc =
to_sde_encoder_phys_shd(phys_enc);
if (!phys_enc)
return;
kfree(shd_enc);
}
static inline
void sde_encoder_phys_shd_irq_ctrl(
struct sde_encoder_phys *phys_enc, bool enable)
{
sde_encoder_phys_shd_control_vblank_irq(phys_enc, enable);
}
static inline
int sde_encoder_phys_shd_get_line_count(
struct sde_encoder_phys *phys)
{
return 0;
}
/**
* sde_encoder_phys_shd_init_ops - initialize writeback operations
* @ops: Pointer to encoder operation table
*/
static void sde_encoder_phys_shd_init_ops(struct sde_encoder_phys_ops *ops)
{
ops->is_master = sde_encoder_phys_shd_is_master;
ops->mode_set = sde_encoder_phys_shd_mode_set;
ops->enable = sde_encoder_phys_shd_enable;
ops->disable = sde_encoder_phys_shd_disable;
ops->destroy = sde_encoder_phys_shd_destroy;
ops->wait_for_commit_done = sde_encoder_phys_shd_wait_for_vblank;
ops->wait_for_vblank = sde_encoder_phys_shd_wait_for_vblank_no_notify;
ops->prepare_for_kickoff = sde_encoder_phys_shd_prepare_for_kickoff;
ops->handle_post_kickoff = sde_encoder_phys_shd_handle_post_kickoff;
ops->trigger_flush = sde_encoder_phys_shd_trigger_flush;
ops->control_vblank_irq = sde_encoder_phys_shd_control_vblank_irq;
ops->wait_for_tx_complete = sde_encoder_phys_shd_wait_for_vblank;
ops->irq_control = sde_encoder_phys_shd_irq_ctrl;
ops->get_line_count = sde_encoder_phys_shd_get_line_count;
}
void *sde_encoder_phys_shd_init(enum sde_intf_type type,
u32 controller_id, void *phys_init_params)
{
struct sde_enc_phys_init_params *p = phys_init_params;
struct sde_encoder_phys *phys_enc;
struct sde_encoder_phys_shd *shd_enc;
struct sde_encoder_irq *irq;
struct sde_shd_hw_ctl *hw_ctl;
struct sde_shd_hw_mixer *hw_lm;
int ret = 0, i;
SDE_DEBUG("\n");
shd_enc = kzalloc(sizeof(*shd_enc), GFP_KERNEL);
if (!shd_enc) {
ret = -ENOMEM;
goto fail_alloc;
}
for (i = 0; i < CRTC_DUAL_MIXERS; i++) {
hw_ctl = kzalloc(sizeof(*hw_ctl), GFP_KERNEL);
if (!hw_ctl) {
ret = -ENOMEM;
goto fail_ctl;
}
shd_enc->hw_ctl[i] = &hw_ctl->base;
hw_lm = kzalloc(sizeof(*hw_lm), GFP_KERNEL);
if (!hw_lm) {
ret = -ENOMEM;
goto fail_ctl;
}
shd_enc->hw_lm[i] = &hw_lm->base;
}
phys_enc = &shd_enc->base;
sde_encoder_phys_shd_init_ops(&phys_enc->ops);
phys_enc->parent = p->parent;
phys_enc->parent_ops = p->parent_ops;
phys_enc->sde_kms = p->sde_kms;
phys_enc->split_role = p->split_role;
phys_enc->intf_mode = INTF_MODE_NONE;
phys_enc->intf_idx = INTF_0 + controller_id;
phys_enc->enc_spinlock = p->enc_spinlock;
atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
irq = &phys_enc->irq[INTR_IDX_VSYNC];
irq->name = "vsync_irq";
irq->intr_type = SDE_IRQ_TYPE_INTF_VSYNC;
irq->intr_idx = INTR_IDX_VSYNC;
irq->cb.func = sde_encoder_phys_shd_vblank_irq;
for (i = 0; i < INTR_IDX_MAX; i++) {
irq = &phys_enc->irq[i];
INIT_LIST_HEAD(&irq->cb.list);
irq->irq_idx = -EINVAL;
irq->hw_idx = -EINVAL;
irq->cb.arg = phys_enc;
}
atomic_set(&phys_enc->vblank_refcount, 0);
atomic_set(&phys_enc->pending_kickoff_cnt, 0);
atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
init_waitqueue_head(&phys_enc->pending_kickoff_wq);
phys_enc->enable_state = SDE_ENC_DISABLED;
return phys_enc;
fail_ctl:
for (i = 0; i < CRTC_DUAL_MIXERS; i++) {
kfree(shd_enc->hw_ctl[i]);
kfree(shd_enc->hw_lm[i]);
}
kfree(shd_enc);
fail_alloc:
return ERR_PTR(ret);
}
|