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 <drm/drm_managed.h> 8 9 #include "dpu_hw_mdss.h" 10 #include "dpu_hwio.h" 11 #include "dpu_hw_catalog.h" 12 #include "dpu_hw_merge3d.h" 13 #include "dpu_kms.h" 14 #include "dpu_trace.h" 15 16 #define MERGE_3D_MUX 0x000 17 #define MERGE_3D_MODE 0x004 18 19 static void dpu_hw_merge_3d_setup_3d_mode(struct dpu_hw_merge_3d *merge_3d, 20 enum dpu_3d_blend_mode mode_3d) 21 { 22 struct dpu_hw_blk_reg_map *c; 23 u32 data; 24 25 26 c = &merge_3d->hw; 27 if (mode_3d == BLEND_3D_NONE) { 28 DPU_REG_WRITE(c, MERGE_3D_MODE, 0); 29 DPU_REG_WRITE(c, MERGE_3D_MUX, 0); 30 } else { 31 data = BIT(0) | ((mode_3d - 1) << 1); 32 DPU_REG_WRITE(c, MERGE_3D_MODE, data); 33 } 34 } 35 36 static void _setup_merge_3d_ops(struct dpu_hw_merge_3d *c, 37 unsigned long features) 38 { 39 c->ops.setup_3d_mode = dpu_hw_merge_3d_setup_3d_mode; 40 }; 41 42 /** 43 * dpu_hw_merge_3d_init() - Initializes the merge_3d driver for the passed 44 * merge3d catalog entry. 45 * @dev: Corresponding device for devres management 46 * @cfg: Pingpong catalog entry for which driver object is required 47 * @addr: Mapped register io address of MDP 48 * Return: Error code or allocated dpu_hw_merge_3d context 49 */ 50 struct dpu_hw_merge_3d *dpu_hw_merge_3d_init(struct drm_device *dev, 51 const struct dpu_merge_3d_cfg *cfg, 52 void __iomem *addr) 53 { 54 struct dpu_hw_merge_3d *c; 55 56 c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL); 57 if (!c) 58 return ERR_PTR(-ENOMEM); 59 60 c->hw.blk_addr = addr + cfg->base; 61 c->hw.log_mask = DPU_DBG_MASK_PINGPONG; 62 63 c->idx = cfg->id; 64 c->caps = cfg; 65 _setup_merge_3d_ops(c, c->caps->features); 66 67 return c; 68 } 69