xref: /linux/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_merge3d.c (revision 8e07e0e3964ca4e23ce7b68e2096fe660a888942)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
3  */
4 
5 #include <linux/iopoll.h>
6 
7 #include "dpu_hw_mdss.h"
8 #include "dpu_hwio.h"
9 #include "dpu_hw_catalog.h"
10 #include "dpu_hw_merge3d.h"
11 #include "dpu_kms.h"
12 #include "dpu_trace.h"
13 
14 #define MERGE_3D_MUX  0x000
15 #define MERGE_3D_MODE 0x004
16 
17 static void dpu_hw_merge_3d_setup_3d_mode(struct dpu_hw_merge_3d *merge_3d,
18 			enum dpu_3d_blend_mode mode_3d)
19 {
20 	struct dpu_hw_blk_reg_map *c;
21 	u32 data;
22 
23 
24 	c = &merge_3d->hw;
25 	if (mode_3d == BLEND_3D_NONE) {
26 		DPU_REG_WRITE(c, MERGE_3D_MODE, 0);
27 		DPU_REG_WRITE(c, MERGE_3D_MUX, 0);
28 	} else {
29 		data = BIT(0) | ((mode_3d - 1) << 1);
30 		DPU_REG_WRITE(c, MERGE_3D_MODE, data);
31 	}
32 }
33 
34 static void _setup_merge_3d_ops(struct dpu_hw_merge_3d *c,
35 				unsigned long features)
36 {
37 	c->ops.setup_3d_mode = dpu_hw_merge_3d_setup_3d_mode;
38 };
39 
40 struct dpu_hw_merge_3d *dpu_hw_merge_3d_init(const struct dpu_merge_3d_cfg *cfg,
41 		void __iomem *addr)
42 {
43 	struct dpu_hw_merge_3d *c;
44 
45 	c = kzalloc(sizeof(*c), GFP_KERNEL);
46 	if (!c)
47 		return ERR_PTR(-ENOMEM);
48 
49 	c->hw.blk_addr = addr + cfg->base;
50 	c->hw.log_mask = DPU_DBG_MASK_PINGPONG;
51 
52 	c->idx = cfg->id;
53 	c->caps = cfg;
54 	_setup_merge_3d_ops(c, c->caps->features);
55 
56 	return c;
57 }
58 
59 void dpu_hw_merge_3d_destroy(struct dpu_hw_merge_3d *hw)
60 {
61 	kfree(hw);
62 }
63