1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
5 #include <linux/delay.h>
7 #include "dpu_hw_ctl.h"
11 #define CTL_LAYER(lm) \
12 (((lm) == LM_5) ? (0x024) : (((lm) - LM_0) * 0x004))
13 #define CTL_LAYER_EXT(lm) \
14 (0x40 + (((lm) - LM_0) * 0x004))
15 #define CTL_LAYER_EXT2(lm) \
16 (0x70 + (((lm) - LM_0) * 0x004))
17 #define CTL_LAYER_EXT3(lm) \
18 (0xA0 + (((lm) - LM_0) * 0x004))
20 #define CTL_FLUSH 0x018
21 #define CTL_START 0x01C
22 #define CTL_PREPARE 0x0d0
23 #define CTL_SW_RESET 0x030
24 #define CTL_LAYER_EXTN_OFFSET 0x40
25 #define CTL_INTF_ACTIVE 0x0F4
26 #define CTL_INTF_FLUSH 0x110
27 #define CTL_INTF_MASTER 0x134
29 #define CTL_MIXER_BORDER_OUT BIT(24)
30 #define CTL_FLUSH_MASK_CTL BIT(17)
32 #define DPU_REG_RESET_TIMEOUT_US 2000
35 static const struct dpu_ctl_cfg
*_ctl_offset(enum dpu_ctl ctl
,
36 const struct dpu_mdss_cfg
*m
,
38 struct dpu_hw_blk_reg_map
*b
)
42 for (i
= 0; i
< m
->ctl_count
; i
++) {
43 if (ctl
== m
->ctl
[i
].id
) {
45 b
->blk_off
= m
->ctl
[i
].base
;
46 b
->length
= m
->ctl
[i
].len
;
47 b
->hwversion
= m
->hwversion
;
48 b
->log_mask
= DPU_DBG_MASK_CTL
;
52 return ERR_PTR(-ENOMEM
);
55 static int _mixer_stages(const struct dpu_lm_cfg
*mixer
, int count
,
61 for (i
= 0; i
< count
; i
++) {
62 if (lm
== mixer
[i
].id
) {
63 stages
= mixer
[i
].sblk
->maxblendstages
;
71 static inline u32
dpu_hw_ctl_get_flush_register(struct dpu_hw_ctl
*ctx
)
73 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
75 return DPU_REG_READ(c
, CTL_FLUSH
);
78 static inline void dpu_hw_ctl_trigger_start(struct dpu_hw_ctl
*ctx
)
80 trace_dpu_hw_ctl_trigger_start(ctx
->pending_flush_mask
,
81 dpu_hw_ctl_get_flush_register(ctx
));
82 DPU_REG_WRITE(&ctx
->hw
, CTL_START
, 0x1);
85 static inline void dpu_hw_ctl_trigger_pending(struct dpu_hw_ctl
*ctx
)
87 trace_dpu_hw_ctl_trigger_prepare(ctx
->pending_flush_mask
,
88 dpu_hw_ctl_get_flush_register(ctx
));
89 DPU_REG_WRITE(&ctx
->hw
, CTL_PREPARE
, 0x1);
92 static inline void dpu_hw_ctl_clear_pending_flush(struct dpu_hw_ctl
*ctx
)
94 trace_dpu_hw_ctl_clear_pending_flush(ctx
->pending_flush_mask
,
95 dpu_hw_ctl_get_flush_register(ctx
));
96 ctx
->pending_flush_mask
= 0x0;
99 static inline void dpu_hw_ctl_update_pending_flush(struct dpu_hw_ctl
*ctx
,
102 trace_dpu_hw_ctl_update_pending_flush(flushbits
,
103 ctx
->pending_flush_mask
);
104 ctx
->pending_flush_mask
|= flushbits
;
107 static inline void dpu_hw_ctl_update_pending_intf_flush(struct dpu_hw_ctl
*ctx
,
110 ctx
->pending_intf_flush_mask
|= flushbits
;
113 static u32
dpu_hw_ctl_get_pending_flush(struct dpu_hw_ctl
*ctx
)
115 return ctx
->pending_flush_mask
;
118 static inline void dpu_hw_ctl_trigger_flush_v1(struct dpu_hw_ctl
*ctx
)
121 if (ctx
->pending_flush_mask
& BIT(INTF_IDX
))
122 DPU_REG_WRITE(&ctx
->hw
, CTL_INTF_FLUSH
,
123 ctx
->pending_intf_flush_mask
);
125 DPU_REG_WRITE(&ctx
->hw
, CTL_FLUSH
, ctx
->pending_flush_mask
);
128 static inline void dpu_hw_ctl_trigger_flush(struct dpu_hw_ctl
*ctx
)
130 trace_dpu_hw_ctl_trigger_pending_flush(ctx
->pending_flush_mask
,
131 dpu_hw_ctl_get_flush_register(ctx
));
132 DPU_REG_WRITE(&ctx
->hw
, CTL_FLUSH
, ctx
->pending_flush_mask
);
135 static uint32_t dpu_hw_ctl_get_bitmask_sspp(struct dpu_hw_ctl
*ctx
,
138 uint32_t flushbits
= 0;
190 static uint32_t dpu_hw_ctl_get_bitmask_mixer(struct dpu_hw_ctl
*ctx
,
193 uint32_t flushbits
= 0;
218 flushbits
|= CTL_FLUSH_MASK_CTL
;
223 static int dpu_hw_ctl_get_bitmask_intf(struct dpu_hw_ctl
*ctx
,
224 u32
*flushbits
, enum dpu_intf intf
)
228 *flushbits
|= BIT(31);
231 *flushbits
|= BIT(30);
234 *flushbits
|= BIT(29);
237 *flushbits
|= BIT(28);
245 static int dpu_hw_ctl_get_bitmask_intf_v1(struct dpu_hw_ctl
*ctx
,
246 u32
*flushbits
, enum dpu_intf intf
)
251 *flushbits
|= BIT(31);
259 static int dpu_hw_ctl_active_get_bitmask_intf(struct dpu_hw_ctl
*ctx
,
260 u32
*flushbits
, enum dpu_intf intf
)
264 *flushbits
|= BIT(0);
267 *flushbits
|= BIT(1);
275 static u32
dpu_hw_ctl_poll_reset_status(struct dpu_hw_ctl
*ctx
, u32 timeout_us
)
277 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
281 timeout
= ktime_add_us(ktime_get(), timeout_us
);
284 * it takes around 30us to have mdp finish resetting its ctl path
285 * poll every 50us so that reset should be completed at 1st poll
288 status
= DPU_REG_READ(c
, CTL_SW_RESET
);
291 usleep_range(20, 50);
292 } while (status
&& ktime_compare_safe(ktime_get(), timeout
) < 0);
297 static int dpu_hw_ctl_reset_control(struct dpu_hw_ctl
*ctx
)
299 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
301 pr_debug("issuing hw ctl reset for ctl:%d\n", ctx
->idx
);
302 DPU_REG_WRITE(c
, CTL_SW_RESET
, 0x1);
303 if (dpu_hw_ctl_poll_reset_status(ctx
, DPU_REG_RESET_TIMEOUT_US
))
309 static int dpu_hw_ctl_wait_reset_status(struct dpu_hw_ctl
*ctx
)
311 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
314 status
= DPU_REG_READ(c
, CTL_SW_RESET
);
319 pr_debug("hw ctl reset is set for ctl:%d\n", ctx
->idx
);
320 if (dpu_hw_ctl_poll_reset_status(ctx
, DPU_REG_RESET_TIMEOUT_US
)) {
321 pr_err("hw recovery is not complete for ctl:%d\n", ctx
->idx
);
328 static void dpu_hw_ctl_clear_all_blendstages(struct dpu_hw_ctl
*ctx
)
330 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
333 for (i
= 0; i
< ctx
->mixer_count
; i
++) {
334 DPU_REG_WRITE(c
, CTL_LAYER(LM_0
+ i
), 0);
335 DPU_REG_WRITE(c
, CTL_LAYER_EXT(LM_0
+ i
), 0);
336 DPU_REG_WRITE(c
, CTL_LAYER_EXT2(LM_0
+ i
), 0);
337 DPU_REG_WRITE(c
, CTL_LAYER_EXT3(LM_0
+ i
), 0);
341 static void dpu_hw_ctl_setup_blendstage(struct dpu_hw_ctl
*ctx
,
342 enum dpu_lm lm
, struct dpu_hw_stage_cfg
*stage_cfg
)
344 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
345 u32 mixercfg
= 0, mixercfg_ext
= 0, mix
, ext
;
346 u32 mixercfg_ext2
= 0, mixercfg_ext3
= 0;
351 stages
= _mixer_stages(ctx
->mixer_hw_caps
, ctx
->mixer_count
, lm
);
355 if (test_bit(DPU_MIXER_SOURCESPLIT
,
356 &ctx
->mixer_hw_caps
->features
))
357 pipes_per_stage
= PIPES_PER_STAGE
;
361 mixercfg
= CTL_MIXER_BORDER_OUT
; /* always set BORDER_OUT */
366 for (i
= 0; i
<= stages
; i
++) {
367 /* overflow to ext register if 'i + 1 > 7' */
371 for (j
= 0 ; j
< pipes_per_stage
; j
++) {
372 enum dpu_sspp_multirect_index rect_index
=
373 stage_cfg
->multirect_index
[i
][j
];
375 switch (stage_cfg
->stage
[i
][j
]) {
377 if (rect_index
== DPU_SSPP_RECT_1
) {
378 mixercfg_ext3
|= ((i
+ 1) & 0xF) << 0;
380 mixercfg
|= mix
<< 0;
381 mixercfg_ext
|= ext
<< 0;
385 if (rect_index
== DPU_SSPP_RECT_1
) {
386 mixercfg_ext3
|= ((i
+ 1) & 0xF) << 4;
388 mixercfg
|= mix
<< 3;
389 mixercfg_ext
|= ext
<< 2;
393 if (rect_index
== DPU_SSPP_RECT_1
) {
394 mixercfg_ext3
|= ((i
+ 1) & 0xF) << 8;
396 mixercfg
|= mix
<< 6;
397 mixercfg_ext
|= ext
<< 4;
401 if (rect_index
== DPU_SSPP_RECT_1
) {
402 mixercfg_ext3
|= ((i
+ 1) & 0xF) << 12;
404 mixercfg
|= mix
<< 26;
405 mixercfg_ext
|= ext
<< 6;
409 mixercfg
|= mix
<< 9;
410 mixercfg_ext
|= ext
<< 8;
413 mixercfg
|= mix
<< 12;
414 mixercfg_ext
|= ext
<< 10;
417 mixercfg
|= mix
<< 15;
418 mixercfg_ext
|= ext
<< 12;
421 mixercfg
|= mix
<< 29;
422 mixercfg_ext
|= ext
<< 14;
425 if (rect_index
== DPU_SSPP_RECT_1
) {
426 mixercfg_ext2
|= ((i
+ 1) & 0xF) << 8;
428 mixercfg
|= mix
<< 18;
429 mixercfg_ext
|= ext
<< 16;
433 if (rect_index
== DPU_SSPP_RECT_1
) {
434 mixercfg_ext2
|= ((i
+ 1) & 0xF) << 12;
436 mixercfg
|= mix
<< 21;
437 mixercfg_ext
|= ext
<< 18;
441 if (rect_index
== DPU_SSPP_RECT_1
) {
442 mixercfg_ext2
|= ((i
+ 1) & 0xF) << 16;
444 mix
|= (i
+ 1) & 0xF;
445 mixercfg_ext2
|= mix
<< 0;
449 if (rect_index
== DPU_SSPP_RECT_1
) {
450 mixercfg_ext2
|= ((i
+ 1) & 0xF) << 20;
452 mix
|= (i
+ 1) & 0xF;
453 mixercfg_ext2
|= mix
<< 4;
457 mixercfg_ext
|= ((i
+ 1) & 0xF) << 20;
460 mixercfg_ext
|= ((i
+ 1) & 0xF) << 26;
469 DPU_REG_WRITE(c
, CTL_LAYER(lm
), mixercfg
);
470 DPU_REG_WRITE(c
, CTL_LAYER_EXT(lm
), mixercfg_ext
);
471 DPU_REG_WRITE(c
, CTL_LAYER_EXT2(lm
), mixercfg_ext2
);
472 DPU_REG_WRITE(c
, CTL_LAYER_EXT3(lm
), mixercfg_ext3
);
476 static void dpu_hw_ctl_intf_cfg_v1(struct dpu_hw_ctl
*ctx
,
477 struct dpu_hw_intf_cfg
*cfg
)
479 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
483 if (cfg
->intf_mode_sel
== DPU_CTL_MODE_SEL_CMD
)
486 intf_active
= DPU_REG_READ(c
, CTL_INTF_ACTIVE
);
487 intf_active
|= BIT(cfg
->intf
- INTF_0
);
489 DPU_REG_WRITE(c
, CTL_TOP
, mode_sel
);
490 DPU_REG_WRITE(c
, CTL_INTF_ACTIVE
, intf_active
);
493 static void dpu_hw_ctl_intf_cfg(struct dpu_hw_ctl
*ctx
,
494 struct dpu_hw_intf_cfg
*cfg
)
496 struct dpu_hw_blk_reg_map
*c
= &ctx
->hw
;
499 intf_cfg
|= (cfg
->intf
& 0xF) << 4;
503 intf_cfg
|= (cfg
->mode_3d
- 0x1) << 20;
506 switch (cfg
->intf_mode_sel
) {
507 case DPU_CTL_MODE_SEL_VID
:
508 intf_cfg
&= ~BIT(17);
509 intf_cfg
&= ~(0x3 << 15);
511 case DPU_CTL_MODE_SEL_CMD
:
513 intf_cfg
|= ((cfg
->stream_sel
& 0x3) << 15);
516 pr_err("unknown interface type %d\n", cfg
->intf_mode_sel
);
520 DPU_REG_WRITE(c
, CTL_TOP
, intf_cfg
);
523 static void _setup_ctl_ops(struct dpu_hw_ctl_ops
*ops
,
526 if (cap
& BIT(DPU_CTL_ACTIVE_CFG
)) {
527 ops
->trigger_flush
= dpu_hw_ctl_trigger_flush_v1
;
528 ops
->setup_intf_cfg
= dpu_hw_ctl_intf_cfg_v1
;
529 ops
->get_bitmask_intf
= dpu_hw_ctl_get_bitmask_intf_v1
;
530 ops
->get_bitmask_active_intf
=
531 dpu_hw_ctl_active_get_bitmask_intf
;
532 ops
->update_pending_intf_flush
=
533 dpu_hw_ctl_update_pending_intf_flush
;
535 ops
->trigger_flush
= dpu_hw_ctl_trigger_flush
;
536 ops
->setup_intf_cfg
= dpu_hw_ctl_intf_cfg
;
537 ops
->get_bitmask_intf
= dpu_hw_ctl_get_bitmask_intf
;
539 ops
->clear_pending_flush
= dpu_hw_ctl_clear_pending_flush
;
540 ops
->update_pending_flush
= dpu_hw_ctl_update_pending_flush
;
541 ops
->get_pending_flush
= dpu_hw_ctl_get_pending_flush
;
542 ops
->get_flush_register
= dpu_hw_ctl_get_flush_register
;
543 ops
->trigger_start
= dpu_hw_ctl_trigger_start
;
544 ops
->trigger_pending
= dpu_hw_ctl_trigger_pending
;
545 ops
->reset
= dpu_hw_ctl_reset_control
;
546 ops
->wait_reset_status
= dpu_hw_ctl_wait_reset_status
;
547 ops
->clear_all_blendstages
= dpu_hw_ctl_clear_all_blendstages
;
548 ops
->setup_blendstage
= dpu_hw_ctl_setup_blendstage
;
549 ops
->get_bitmask_sspp
= dpu_hw_ctl_get_bitmask_sspp
;
550 ops
->get_bitmask_mixer
= dpu_hw_ctl_get_bitmask_mixer
;
553 static struct dpu_hw_blk_ops dpu_hw_ops
;
555 struct dpu_hw_ctl
*dpu_hw_ctl_init(enum dpu_ctl idx
,
557 const struct dpu_mdss_cfg
*m
)
559 struct dpu_hw_ctl
*c
;
560 const struct dpu_ctl_cfg
*cfg
;
562 c
= kzalloc(sizeof(*c
), GFP_KERNEL
);
564 return ERR_PTR(-ENOMEM
);
566 cfg
= _ctl_offset(idx
, m
, addr
, &c
->hw
);
567 if (IS_ERR_OR_NULL(cfg
)) {
569 pr_err("failed to create dpu_hw_ctl %d\n", idx
);
570 return ERR_PTR(-EINVAL
);
574 _setup_ctl_ops(&c
->ops
, c
->caps
->features
);
576 c
->mixer_count
= m
->mixer_count
;
577 c
->mixer_hw_caps
= m
->mixer
;
579 dpu_hw_blk_init(&c
->base
, DPU_HW_BLK_CTL
, idx
, &dpu_hw_ops
);
584 void dpu_hw_ctl_destroy(struct dpu_hw_ctl
*ctx
)
587 dpu_hw_blk_destroy(&ctx
->base
);