1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
5 #include <drm/drm_managed.h>
8 #include "dpu_hw_catalog.h"
10 #include "dpu_hw_dspp.h"
17 #define PCC_RED_R_OFF 0x10
18 #define PCC_RED_G_OFF 0x1C
19 #define PCC_RED_B_OFF 0x28
20 #define PCC_GREEN_R_OFF 0x14
21 #define PCC_GREEN_G_OFF 0x20
22 #define PCC_GREEN_B_OFF 0x2C
23 #define PCC_BLUE_R_OFF 0x18
24 #define PCC_BLUE_G_OFF 0x24
25 #define PCC_BLUE_B_OFF 0x30
27 static void dpu_setup_dspp_pcc(struct dpu_hw_dspp *ctx,
28 struct dpu_hw_pcc_cfg *cfg)
34 DRM_ERROR("invalid ctx %pK\n", ctx);
38 base = ctx->cap->sblk->pcc.base;
41 DRM_ERROR("invalid ctx %pK pcc base 0x%x\n", ctx, base);
46 DRM_DEBUG_DRIVER("disable pcc feature\n");
47 DPU_REG_WRITE(&ctx->hw, base, PCC_DIS);
51 DPU_REG_WRITE(&ctx->hw, base + PCC_RED_R_OFF, cfg->r.r);
52 DPU_REG_WRITE(&ctx->hw, base + PCC_RED_G_OFF, cfg->r.g);
53 DPU_REG_WRITE(&ctx->hw, base + PCC_RED_B_OFF, cfg->r.b);
55 DPU_REG_WRITE(&ctx->hw, base + PCC_GREEN_R_OFF, cfg->g.r);
56 DPU_REG_WRITE(&ctx->hw, base + PCC_GREEN_G_OFF, cfg->g.g);
57 DPU_REG_WRITE(&ctx->hw, base + PCC_GREEN_B_OFF, cfg->g.b);
59 DPU_REG_WRITE(&ctx->hw, base + PCC_BLUE_R_OFF, cfg->b.r);
60 DPU_REG_WRITE(&ctx->hw, base + PCC_BLUE_G_OFF, cfg->b.g);
61 DPU_REG_WRITE(&ctx->hw, base + PCC_BLUE_B_OFF, cfg->b.b);
63 DPU_REG_WRITE(&ctx->hw, base, PCC_EN);
66 static void _setup_dspp_ops(struct dpu_hw_dspp *c,
67 unsigned long features)
69 if (test_bit(DPU_DSPP_PCC, &features))
70 c->ops.setup_pcc = dpu_setup_dspp_pcc;
74 * dpu_hw_dspp_init() - Initializes the DSPP hw driver object.
75 * should be called once before accessing every DSPP.
76 * @dev: Corresponding device for devres management
77 * @cfg: DSPP catalog entry for which driver object is required
78 * @addr: Mapped register io address of MDP
79 * Return: pointer to structure or ERR_PTR
81 struct dpu_hw_dspp *dpu_hw_dspp_init(struct drm_device *dev,
82 const struct dpu_dspp_cfg *cfg,
85 struct dpu_hw_dspp *c;
88 return ERR_PTR(-EINVAL);
90 c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
92 return ERR_PTR(-ENOMEM);
94 c->hw.blk_addr = addr + cfg->base;
95 c->hw.log_mask = DPU_DBG_MASK_DSPP;
100 _setup_dspp_ops(c, c->cap->features);