<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Daniel Vetter <<a href="mailto:daniel@ffwll.ch">daniel@ffwll.ch</a>> 于2020年7月29日周三 上午5:51写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Jul 28, 2020 at 12:08 PM Kevin Tang <<a href="mailto:kevin3.tang@gmail.com" target="_blank">kevin3.tang@gmail.com</a>> wrote:<br>
><br>
> From: Kevin Tang <<a href="mailto:kevin.tang@unisoc.com" target="_blank">kevin.tang@unisoc.com</a>><br>
><br>
> Adds DPU(Display Processor Unit) support for the Unisoc's display subsystem.<br>
> It's support multi planes, scaler, rotation, PQ(Picture Quality) and more.<br>
><br>
> RFC v6:<br>
> - Access registers via readl/writel<br>
> - Checking for unsupported KMS properties (format, rotation, blend_mode, etc) on plane_check ops<br>
> - Remove always true checks for dpu core ops<br>
><br>
> Cc: Orson Zhai <<a href="mailto:orsonzhai@gmail.com" target="_blank">orsonzhai@gmail.com</a>><br>
> Cc: Chunyan Zhang <<a href="mailto:zhang.lyra@gmail.com" target="_blank">zhang.lyra@gmail.com</a>><br>
> Signed-off-by: Kevin Tang <<a href="mailto:kevin.tang@unisoc.com" target="_blank">kevin.tang@unisoc.com</a>><br>
<br>
Quickly scrolled through this, and the entire thing very much leaves a<br>
midlayer heavy aftertaste. Do we really need stuff like struct dpu_layer<br>
and struct dpu_core_ops? They only seem to complicate the code base, and<br>
seem to have no real reason. The indirection with first computing register<br>
values into a sprd_plane/crtc structure, and then writing it into hardware<br>
is also a bit much - I recommend to only do that if you have to compute<br>
values in _check to validate them, so that the computation doesn't have to<br>
be repeated in the commit phase functions.<br>
<br>
Also, the layer and pending_flips stuff in sprd_dpu don't work with<br>
atomic, that races. You have to put all that stuff into state objects, or<br>
if it's some data shared with interrupt handlers (doesn't seem to be the<br>
case here), it needs its own locking, and any data you need in the<br>
interrupt handler must be copied over.<br>
<br>
Also no devm_kzalloc for anything containined a drm_* structure, that's<br>
the wrong lifetime.<br>
<br>
So yeah high level review is that I think this driver would benefit a lot<br>
from a pile of demidlayer.<br>
<br>
Cheers, Daniel<br></blockquote><div>Hi Daniel,</div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>After a long time of thinking, </span></span></span>I think you are right, the stuff layer of dpu_layer and dpu_core_ops</span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>maybe no need for us now. So i will delete "dpu_layer" on patch v3, and commit<span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span> layer information directly</span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>in atomic_update.</span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><br></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>Because only one dpu h/w verison been submitt now, so i have delete "dpu_core_ops" on patch v2.</span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>After the basic version is submitted,<span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span> <span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>I will start preparing for the support of multiple h/w versions,</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>but it will take some time, <span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>because our different h/w versions all have some differences.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><br></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>Only drm format convert to dpu format need to check on atomic_check,<span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span> i'm not sure if drm framework</span></span></span></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>will help filter out illegal formats, so i add layer format check on atomic_check,<br></span></span></span></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>as for rotation, blend mode, i think it just give a default value, it maybe work well.<br></span></span></span></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><br></span></span></span></span></span></span></span></span></span></span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-RichText gmail-ztext gmail-CopyrightRichText-richText"><span class="gmail-RichText gmail-ztext gmail-CopyrightRichText-richText">Best Wishes</span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> ---<br>
> drivers/gpu/drm/sprd/Makefile | 5 +-<br>
> drivers/gpu/drm/sprd/dpu/Makefile | 3 +<br>
> drivers/gpu/drm/sprd/dpu/dpu_r2p0.c | 503 ++++++++++++++++++++++++++++<br>
> drivers/gpu/drm/sprd/sprd_dpu.c | 646 ++++++++++++++++++++++++++++++++++++<br>
> drivers/gpu/drm/sprd/sprd_dpu.h | 187 +++++++++++<br>
> drivers/gpu/drm/sprd/sprd_drm.c | 1 +<br>
> drivers/gpu/drm/sprd/sprd_drm.h | 2 +<br>
> 7 files changed, 1346 insertions(+), 1 deletion(-)<br>
> create mode 100644 drivers/gpu/drm/sprd/dpu/Makefile<br>
> create mode 100644 drivers/gpu/drm/sprd/dpu/dpu_r2p0.c<br>
> create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.c<br>
> create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.h<br>
><br>
> diff --git a/drivers/gpu/drm/sprd/Makefile b/drivers/gpu/drm/sprd/Makefile<br>
> index 86d95d9..88ab32a 100644<br>
> --- a/drivers/gpu/drm/sprd/Makefile<br>
> +++ b/drivers/gpu/drm/sprd/Makefile<br>
> @@ -2,4 +2,7 @@<br>
><br>
> subdir-ccflags-y += -I$(srctree)/$(src)<br>
><br>
> -obj-y := sprd_drm.o<br>
> +obj-y := sprd_drm.o \<br>
> + sprd_dpu.o<br>
> +<br>
> +obj-y += dpu/<br>
> diff --git a/drivers/gpu/drm/sprd/dpu/Makefile b/drivers/gpu/drm/sprd/dpu/Makefile<br>
> new file mode 100644<br>
> index 0000000..40278b6<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dpu/Makefile<br>
> @@ -0,0 +1,3 @@<br>
> +# SPDX-License-Identifier: GPL-2.0<br>
> +<br>
> +obj-y += dpu_r2p0.o<br>
> diff --git a/drivers/gpu/drm/sprd/dpu/dpu_r2p0.c b/drivers/gpu/drm/sprd/dpu/dpu_r2p0.c<br>
> new file mode 100644<br>
> index 0000000..4b9521d<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dpu/dpu_r2p0.c<br>
> @@ -0,0 +1,503 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <linux/delay.h><br>
> +#include <linux/io.h><br>
> +#include <linux/wait.h><br>
> +#include <linux/workqueue.h><br>
> +<br>
> +#include "sprd_dpu.h"<br>
> +<br>
> +/* DPU registers size, 4 Bytes(32 Bits) */<br>
> +#define DPU_REG_SIZE 0x04<br>
> +<br>
> +/* Layer registers offset */<br>
> +#define DPU_LAY_REG_OFFSET 0x0C<br>
> +<br>
> +#define DPU_LAY_REG(reg, index) \<br>
> + (reg + index * DPU_LAY_REG_OFFSET * DPU_REG_SIZE)<br>
> +<br>
> +#define DPU_REG_RD(reg) readl_relaxed(reg)<br>
> +<br>
> +#define DPU_REG_WR(reg, mask) writel_relaxed(mask, reg)<br>
> +<br>
> +#define DPU_REG_SET(reg, mask) \<br>
> + writel_relaxed(readl_relaxed(reg) | mask, reg)<br>
> +<br>
> +#define DPU_REG_CLR(reg, mask) \<br>
> + writel_relaxed(readl_relaxed(reg) & ~mask, reg)<br>
> +<br>
> +/* Global control registers */<br>
> +#define REG_DPU_CTRL 0x04<br>
> +#define REG_DPU_CFG0 0x08<br>
> +#define REG_DPU_CFG1 0x0C<br>
> +#define REG_DPU_CFG2 0x10<br>
> +#define REG_PANEL_SIZE 0x20<br>
> +#define REG_BLEND_SIZE 0x24<br>
> +#define REG_BG_COLOR 0x2C<br>
> +<br>
> +/* Layer0 control registers */<br>
> +#define REG_LAY_BASE_ADDR0 0x30<br>
> +#define REG_LAY_BASE_ADDR1 0x34<br>
> +#define REG_LAY_BASE_ADDR2 0x38<br>
> +#define REG_LAY_CTRL 0x40<br>
> +#define REG_LAY_SIZE 0x44<br>
> +#define REG_LAY_PITCH 0x48<br>
> +#define REG_LAY_POS 0x4C<br>
> +#define REG_LAY_ALPHA 0x50<br>
> +#define REG_LAY_PALLETE 0x58<br>
> +#define REG_LAY_CROP_START 0x5C<br>
> +<br>
> +/* Interrupt control registers */<br>
> +#define REG_DPU_INT_EN 0x1E0<br>
> +#define REG_DPU_INT_CLR 0x1E4<br>
> +#define REG_DPU_INT_STS 0x1E8<br>
> +<br>
> +/* DPI control registers */<br>
> +#define REG_DPI_CTRL 0x1F0<br>
> +#define REG_DPI_H_TIMING 0x1F4<br>
> +#define REG_DPI_V_TIMING 0x1F8<br>
> +<br>
> +/* MMU control registers */<br>
> +#define REG_MMU_EN 0x800<br>
> +#define REG_MMU_VPN_RANGE 0x80C<br>
> +#define REG_MMU_VAOR_ADDR_RD 0x818<br>
> +#define REG_MMU_VAOR_ADDR_WR 0x81C<br>
> +#define REG_MMU_INV_ADDR_RD 0x820<br>
> +#define REG_MMU_INV_ADDR_WR 0x824<br>
> +#define REG_MMU_PPN1 0x83C<br>
> +#define REG_MMU_RANGE1 0x840<br>
> +#define REG_MMU_PPN2 0x844<br>
> +#define REG_MMU_RANGE2 0x848<br>
> +<br>
> +/* Global control bits */<br>
> +#define BIT_DPU_RUN BIT(0)<br>
> +#define BIT_DPU_STOP BIT(1)<br>
> +#define BIT_DPU_REG_UPDATE BIT(2)<br>
> +#define BIT_DPU_IF_EDPI BIT(0)<br>
> +#define BIT_DPU_COEF_NARROW_RANGE BIT(4)<br>
> +#define BIT_DPU_Y2R_COEF_ITU709_STANDARD BIT(5)<br>
> +<br>
> +/* Layer control bits */<br>
> +#define BIT_DPU_LAY_EN BIT(0)<br>
> +<br>
> +/* Interrupt control & status bits */<br>
> +#define BIT_DPU_INT_DONE BIT(0)<br>
> +#define BIT_DPU_INT_TE BIT(1)<br>
> +#define BIT_DPU_INT_ERR BIT(2)<br>
> +#define BIT_DPU_INT_UPDATE_DONE BIT(4)<br>
> +#define BIT_DPU_INT_VSYNC BIT(5)<br>
> +#define BIT_DPU_INT_FBC_PLD_ERR BIT(8)<br>
> +#define BIT_DPU_INT_FBC_HDR_ERR BIT(9)<br>
> +#define BIT_DPU_INT_MMU_VAOR_RD BIT(16)<br>
> +#define BIT_DPU_INT_MMU_VAOR_WR BIT(17)<br>
> +#define BIT_DPU_INT_MMU_INV_RD BIT(18)<br>
> +#define BIT_DPU_INT_MMU_INV_WR BIT(19)<br>
> +<br>
> +/* DPI control bits */<br>
> +#define BIT_DPU_EDPI_TE_EN BIT(8)<br>
> +#define BIT_DPU_EDPI_FROM_EXTERNAL_PAD BIT(10)<br>
> +#define BIT_DPU_DPI_HALT_EN BIT(16)<br>
> +<br>
> +<br>
> +static u32 check_mmu_isr(struct dpu_context *ctx, u32 reg_val)<br>
> +{<br>
> + u32 mmu_mask = BIT_DPU_INT_MMU_VAOR_RD |<br>
> + BIT_DPU_INT_MMU_VAOR_WR |<br>
> + BIT_DPU_INT_MMU_INV_RD |<br>
> + BIT_DPU_INT_MMU_INV_WR;<br>
> + u32 val = reg_val & mmu_mask;<br>
> + int i;<br>
> +<br>
> + if (val) {<br>
> + DRM_ERROR("--- iommu interrupt err: 0x%04x ---\n", val);<br>
> +<br>
> + if (val & BIT_DPU_INT_MMU_INV_RD)<br>
> + DRM_ERROR("iommu invalid read error, addr: 0x%08x\n",<br>
> + DPU_REG_RD(ctx->base + REG_MMU_INV_ADDR_RD));<br>
> + if (val & BIT_DPU_INT_MMU_INV_WR)<br>
> + DRM_ERROR("iommu invalid write error, addr: 0x%08x\n",<br>
> + DPU_REG_RD(ctx->base + REG_MMU_INV_ADDR_WR));<br>
> + if (val & BIT_DPU_INT_MMU_VAOR_RD)<br>
> + DRM_ERROR("iommu va out of range read error, addr: 0x%08x\n",<br>
> + DPU_REG_RD(ctx->base + REG_MMU_VAOR_ADDR_RD));<br>
> + if (val & BIT_DPU_INT_MMU_VAOR_WR)<br>
> + DRM_ERROR("iommu va out of range write error, addr: 0x%08x\n",<br>
> + DPU_REG_RD(ctx->base + REG_MMU_VAOR_ADDR_WR));<br>
> +<br>
> + for (i = 0; i < 8; i++) {<br>
> + reg_val = DPU_REG_RD(ctx->base + DPU_LAY_REG(REG_LAY_CTRL, i));<br>
> + if (reg_val & 0x1)<br>
> + DRM_INFO("layer%d: 0x%08x 0x%08x 0x%08x ctrl: 0x%08x\n", i,<br>
> + DPU_REG_RD(ctx->base + DPU_LAY_REG(REG_LAY_BASE_ADDR0, i)),<br>
> + DPU_REG_RD(ctx->base + DPU_LAY_REG(REG_LAY_BASE_ADDR1, i)),<br>
> + DPU_REG_RD(ctx->base + DPU_LAY_REG(REG_LAY_BASE_ADDR2, i)),<br>
> + DPU_REG_RD(ctx->base + DPU_LAY_REG(REG_LAY_CTRL, i)));<br>
> + }<br>
> + }<br>
> +<br>
> + return val;<br>
> +}<br>
> +<br>
> +static void dpu_clean_all(struct dpu_context *ctx)<br>
> +{<br>
> + int i;<br>
> +<br>
> + for (i = 0; i < 8; i++)<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_CTRL, i), 0x00);<br>
> +}<br>
> +<br>
> +static u32 dpu_isr(struct dpu_context *ctx)<br>
> +{<br>
> + u32 reg_val, int_mask = 0;<br>
> +<br>
> + reg_val = DPU_REG_RD(ctx->base + REG_DPU_INT_STS);<br>
> +<br>
> + /* disable err interrupt */<br>
> + if (reg_val & BIT_DPU_INT_ERR)<br>
> + int_mask |= BIT_DPU_INT_ERR;<br>
> +<br>
> + /* dpu update done isr */<br>
> + if (reg_val & BIT_DPU_INT_UPDATE_DONE) {<br>
> + ctx->evt_update = true;<br>
> + wake_up_interruptible_all(&ctx->wait_queue);<br>
> + }<br>
> +<br>
> + /* dpu stop done isr */<br>
> + if (reg_val & BIT_DPU_INT_DONE) {<br>
> + ctx->evt_stop = true;<br>
> + wake_up_interruptible_all(&ctx->wait_queue);<br>
> + }<br>
> +<br>
> + /* dpu ifbc payload error isr */<br>
> + if (reg_val & BIT_DPU_INT_FBC_PLD_ERR) {<br>
> + int_mask |= BIT_DPU_INT_FBC_PLD_ERR;<br>
> + DRM_ERROR("dpu ifbc payload error\n");<br>
> + }<br>
> +<br>
> + /* dpu ifbc header error isr */<br>
> + if (reg_val & BIT_DPU_INT_FBC_HDR_ERR) {<br>
> + int_mask |= BIT_DPU_INT_FBC_HDR_ERR;<br>
> + DRM_ERROR("dpu ifbc header error\n");<br>
> + }<br>
> +<br>
> + int_mask |= check_mmu_isr(ctx, reg_val);<br>
> +<br>
> + DPU_REG_WR(ctx->base + REG_DPU_INT_CLR, reg_val);<br>
> + DPU_REG_CLR(ctx->base + REG_DPU_INT_EN, int_mask);<br>
> +<br>
> + return reg_val;<br>
> +}<br>
> +<br>
> +static int dpu_wait_stop_done(struct dpu_context *ctx)<br>
> +{<br>
> + int rc;<br>
> +<br>
> + if (ctx->stopped)<br>
> + return 0;<br>
> +<br>
> + rc = wait_event_interruptible_timeout(ctx->wait_queue, ctx->evt_stop,<br>
> + msecs_to_jiffies(500));<br>
> + ctx->evt_stop = false;<br>
> +<br>
> + ctx->stopped = true;<br>
> +<br>
> + if (!rc) {<br>
> + DRM_ERROR("dpu wait for stop done time out!\n");<br>
> + return -ETIMEDOUT;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int dpu_wait_update_done(struct dpu_context *ctx)<br>
> +{<br>
> + int rc;<br>
> +<br>
> + ctx->evt_update = false;<br>
> +<br>
> + rc = wait_event_interruptible_timeout(ctx->wait_queue, ctx->evt_update,<br>
> + msecs_to_jiffies(500));<br>
> +<br>
> + if (!rc) {<br>
> + DRM_ERROR("dpu wait for reg update done time out!\n");<br>
> + return -ETIMEDOUT;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void dpu_stop(struct dpu_context *ctx)<br>
> +{<br>
> + if (ctx->if_type == SPRD_DPU_IF_DPI)<br>
> + DPU_REG_SET(ctx->base + REG_DPU_CTRL, BIT_DPU_STOP);<br>
> +<br>
> + dpu_wait_stop_done(ctx);<br>
> +}<br>
> +<br>
> +static void dpu_run(struct dpu_context *ctx)<br>
> +{<br>
> + DPU_REG_SET(ctx->base + REG_DPU_CTRL, BIT_DPU_RUN);<br>
> +<br>
> + ctx->stopped = false;<br>
> +}<br>
> +<br>
> +static void dpu_init(struct dpu_context *ctx)<br>
> +{<br>
> + u32 reg_val, size;<br>
> +<br>
> + DPU_REG_WR(ctx->base + REG_BG_COLOR, 0x00);<br>
> +<br>
> + size = (ctx->vm.vactive << 16) | ctx->vm.hactive;<br>
> +<br>
> + DPU_REG_WR(ctx->base + REG_PANEL_SIZE, size);<br>
> + DPU_REG_WR(ctx->base + REG_BLEND_SIZE, size);<br>
> +<br>
> + reg_val = BIT_DPU_COEF_NARROW_RANGE | BIT_DPU_Y2R_COEF_ITU709_STANDARD;<br>
> + DPU_REG_WR(ctx->base + REG_DPU_CFG0, reg_val);<br>
> + DPU_REG_WR(ctx->base + REG_DPU_CFG1, 0x004466da);<br>
> + DPU_REG_WR(ctx->base + REG_DPU_CFG2, 0x00);<br>
> +<br>
> + if (ctx->stopped)<br>
> + dpu_clean_all(ctx);<br>
> +<br>
> + DPU_REG_WR(ctx->base + REG_MMU_EN, 0x00);<br>
> + DPU_REG_WR(ctx->base + REG_MMU_PPN1, 0x00);<br>
> + DPU_REG_WR(ctx->base + REG_MMU_RANGE1, 0xffff);<br>
> + DPU_REG_WR(ctx->base + REG_MMU_PPN2, 0x00);<br>
> + DPU_REG_WR(ctx->base + REG_MMU_RANGE2, 0xffff);<br>
> + DPU_REG_WR(ctx->base + REG_MMU_VPN_RANGE, 0x1ffff);<br>
> +<br>
> + DPU_REG_WR(ctx->base + REG_DPU_INT_CLR, 0xffff);<br>
> +}<br>
> +<br>
> +static void dpu_fini(struct dpu_context *ctx)<br>
> +{<br>
> + DPU_REG_WR(ctx->base + REG_DPU_INT_EN, 0x00);<br>
> + DPU_REG_WR(ctx->base + REG_DPU_INT_CLR, 0xff);<br>
> +}<br>
> +<br>
> +static void dpu_layer(struct dpu_context *ctx,<br>
> + struct dpu_layer *hwlayer)<br>
> +{<br>
> + const struct drm_format_info *info;<br>
> + u32 size, offset, ctrl, pitch;<br>
> + int i;<br>
> +<br>
> + offset = (hwlayer->dst_x & 0xffff) | ((hwlayer->dst_y) << 16);<br>
> +<br>
> + if (hwlayer->src_w && hwlayer->src_h)<br>
> + size = (hwlayer->src_w & 0xffff) | ((hwlayer->src_h) << 16);<br>
> + else<br>
> + size = (hwlayer->dst_w & 0xffff) | ((hwlayer->dst_h) << 16);<br>
> +<br>
> + for (i = 0; i < hwlayer->planes; i++)<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_BASE_ADDR0,<br>
> + hwlayer->index), hwlayer->addr[i]);<br>
> +<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_POS,<br>
> + hwlayer->index), offset);<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_SIZE,<br>
> + hwlayer->index), size);<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_CROP_START,<br>
> + hwlayer->index), hwlayer->src_y << 16 | hwlayer->src_x);<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_ALPHA,<br>
> + hwlayer->index), hwlayer->alpha);<br>
> +<br>
> + info = drm_format_info(hwlayer->format);<br>
> + if (hwlayer->planes == 3) {<br>
> + /* UV pitch is 1/2 of Y pitch*/<br>
> + pitch = (hwlayer->pitch[0] / info->cpp[0]) |<br>
> + (hwlayer->pitch[0] / info->cpp[0] << 15);<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_PITCH,<br>
> + hwlayer->index), pitch);<br>
> + } else {<br>
> + pitch = hwlayer->pitch[0] / info->cpp[0];<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_PITCH,<br>
> + hwlayer->index), pitch);<br>
> + }<br>
> +<br>
> + ctrl = hwlayer->format |<br>
> + hwlayer->blending |<br>
> + (hwlayer->rotation & 0x7) << 20;<br>
> +<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_CTRL,<br>
> + hwlayer->index), ctrl);<br>
> + DPU_REG_WR(ctx->base + DPU_LAY_REG(REG_LAY_CTRL,<br>
> + hwlayer->index), BIT_DPU_LAY_EN);<br>
> +<br>
> + DRM_DEBUG("dst_x = %d, dst_y = %d, dst_w = %d, dst_h = %d\n",<br>
> + hwlayer->dst_x, hwlayer->dst_y,<br>
> + hwlayer->dst_w, hwlayer->dst_h);<br>
> + DRM_DEBUG("start_x = %d, start_y = %d, start_w = %d, start_h = %d\n",<br>
> + hwlayer->src_x, hwlayer->src_y,<br>
> + hwlayer->src_w, hwlayer->src_h);<br>
> +}<br>
> +<br>
> +static void dpu_flip(struct dpu_context *ctx,<br>
> + struct dpu_layer layers[], u8 count)<br>
> +{<br>
> + int i;<br>
> + u32 reg_val;<br>
> +<br>
> + /*<br>
> + * Make sure the dpu is in stop status. DPU_R2P0 has no shadow<br>
> + * registers in EDPI mode. So the config registers can only be<br>
> + * updated in the rising edge of DPU_RUN bit.<br>
> + */<br>
> + if (ctx->if_type == SPRD_DPU_IF_EDPI)<br>
> + dpu_wait_stop_done(ctx);<br>
> +<br>
> + /* reset the bgcolor to black */<br>
> + DPU_REG_WR(ctx->base + REG_BG_COLOR, 0x00);<br>
> +<br>
> + /* disable all the layers */<br>
> + dpu_clean_all(ctx);<br>
> +<br>
> + /* start configure dpu layers */<br>
> + for (i = 0; i < count; i++)<br>
> + dpu_layer(ctx, &layers[i]);<br>
> +<br>
> + /* update trigger and wait */<br>
> + if (ctx->if_type == SPRD_DPU_IF_DPI) {<br>
> + if (!ctx->stopped) {<br>
> + DPU_REG_SET(ctx->base + REG_DPU_CTRL, BIT_DPU_REG_UPDATE);<br>
> + dpu_wait_update_done(ctx);<br>
> + }<br>
> +<br>
> + DPU_REG_SET(ctx->base + REG_DPU_INT_EN, BIT_DPU_INT_ERR);<br>
> + } else if (ctx->if_type == SPRD_DPU_IF_EDPI) {<br>
> + DPU_REG_SET(ctx->base + REG_DPU_CTRL, BIT_DPU_RUN);<br>
> +<br>
> + ctx->stopped = false;<br>
> + }<br>
> +<br>
> + /*<br>
> + * If the following interrupt was disabled in isr,<br>
> + * re-enable it.<br>
> + */<br>
> + reg_val = BIT_DPU_INT_FBC_PLD_ERR |<br>
> + BIT_DPU_INT_FBC_HDR_ERR |<br>
> + BIT_DPU_INT_MMU_VAOR_RD |<br>
> + BIT_DPU_INT_MMU_VAOR_WR |<br>
> + BIT_DPU_INT_MMU_INV_RD |<br>
> + BIT_DPU_INT_MMU_INV_WR;<br>
> + DPU_REG_SET(ctx->base + REG_DPU_INT_EN, reg_val);<br>
> +<br>
> +}<br>
> +<br>
> +static void dpu_dpi_init(struct dpu_context *ctx)<br>
> +{<br>
> + u32 int_mask = 0;<br>
> + u32 reg_val;<br>
> +<br>
> + if (ctx->if_type == SPRD_DPU_IF_DPI) {<br>
> + /* use dpi as interface */<br>
> + DPU_REG_CLR(ctx->base + REG_DPU_CFG0, BIT_DPU_IF_EDPI);<br>
> +<br>
> + /* disable Halt function for SPRD DSI */<br>
> + DPU_REG_CLR(ctx->base + REG_DPI_CTRL, BIT_DPU_DPI_HALT_EN);<br>
> +<br>
> + /* select te from external pad */<br>
> + DPU_REG_SET(ctx->base + REG_DPI_CTRL, BIT_DPU_EDPI_FROM_EXTERNAL_PAD);<br>
> +<br>
> + /* set dpi timing */<br>
> + reg_val = ctx->vm.hsync_len << 0 |<br>
> + ctx->vm.hback_porch << 8 |<br>
> + ctx->vm.hfront_porch << 20;<br>
> + DPU_REG_WR(ctx->base + REG_DPI_H_TIMING, reg_val);<br>
> +<br>
> + reg_val = ctx->vm.vsync_len << 0 |<br>
> + ctx->vm.vback_porch << 8 |<br>
> + ctx->vm.vfront_porch << 20;<br>
> + DPU_REG_WR(ctx->base + REG_DPI_V_TIMING, reg_val);<br>
> +<br>
> + if (ctx->vm.vsync_len + ctx->vm.vback_porch < 32)<br>
> + DRM_WARN("Warning: (vsync + vbp) < 32, "<br>
> + "underflow risk!\n");<br>
> +<br>
> + /* enable dpu update done INT */<br>
> + int_mask |= BIT_DPU_INT_UPDATE_DONE;<br>
> + /* enable dpu DONE INT */<br>
> + int_mask |= BIT_DPU_INT_DONE;<br>
> + /* enable dpu dpi vsync */<br>
> + int_mask |= BIT_DPU_INT_VSYNC;<br>
> + /* enable dpu TE INT */<br>
> + int_mask |= BIT_DPU_INT_TE;<br>
> + /* enable underflow err INT */<br>
> + int_mask |= BIT_DPU_INT_ERR;<br>
> + } else if (ctx->if_type == SPRD_DPU_IF_EDPI) {<br>
> + /* use edpi as interface */<br>
> + DPU_REG_SET(ctx->base + REG_DPU_CFG0, BIT_DPU_IF_EDPI);<br>
> +<br>
> + /* use external te */<br>
> + DPU_REG_SET(ctx->base + REG_DPI_CTRL, BIT_DPU_EDPI_FROM_EXTERNAL_PAD);<br>
> +<br>
> + /* enable te */<br>
> + DPU_REG_SET(ctx->base + REG_DPI_CTRL, BIT_DPU_EDPI_TE_EN);<br>
> +<br>
> + /* enable stop DONE INT */<br>
> + int_mask |= BIT_DPU_INT_DONE;<br>
> + /* enable TE INT */<br>
> + int_mask |= BIT_DPU_INT_TE;<br>
> + }<br>
> +<br>
> + /* enable ifbc payload error INT */<br>
> + int_mask |= BIT_DPU_INT_FBC_PLD_ERR;<br>
> + /* enable ifbc header error INT */<br>
> + int_mask |= BIT_DPU_INT_FBC_HDR_ERR;<br>
> + /* enable iommu va out of range read error INT */<br>
> + int_mask |= BIT_DPU_INT_MMU_VAOR_RD;<br>
> + /* enable iommu va out of range write error INT */<br>
> + int_mask |= BIT_DPU_INT_MMU_VAOR_WR;<br>
> + /* enable iommu invalid read error INT */<br>
> + int_mask |= BIT_DPU_INT_MMU_INV_RD;<br>
> + /* enable iommu invalid write error INT */<br>
> + int_mask |= BIT_DPU_INT_MMU_INV_WR;<br>
> +<br>
> + DPU_REG_WR(ctx->base + REG_DPU_INT_EN, int_mask);<br>
> +}<br>
> +<br>
> +static void enable_vsync(struct dpu_context *ctx)<br>
> +{<br>
> + DPU_REG_SET(ctx->base + REG_DPU_INT_EN, BIT_DPU_INT_VSYNC);<br>
> +}<br>
> +<br>
> +static void disable_vsync(struct dpu_context *ctx)<br>
> +{<br>
> + DPU_REG_CLR(ctx->base + REG_DPU_INT_EN, BIT_DPU_INT_VSYNC);<br>
> +}<br>
> +<br>
> +static const u32 primary_fmts[] = {<br>
> + DRM_FORMAT_XRGB8888, DRM_FORMAT_XBGR8888,<br>
> + DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888,<br>
> + DRM_FORMAT_RGBA8888, DRM_FORMAT_BGRA8888,<br>
> + DRM_FORMAT_RGBX8888, DRM_FORMAT_RGB565,<br>
> + DRM_FORMAT_BGR565, DRM_FORMAT_NV12,<br>
> + DRM_FORMAT_NV21, DRM_FORMAT_NV16,<br>
> + DRM_FORMAT_NV61, DRM_FORMAT_YUV420,<br>
> + DRM_FORMAT_YVU420,<br>
> +};<br>
> +<br>
> +static void dpu_capability(struct dpu_context *ctx,<br>
> + struct dpu_capability *cap)<br>
> +{<br>
> + cap->max_layers = 6;<br>
> + cap->fmts_ptr = primary_fmts;<br>
> + cap->fmts_cnt = ARRAY_SIZE(primary_fmts);<br>
> +}<br>
> +<br>
> +const struct dpu_core_ops dpu_r2p0_core_ops = {<br>
> + .init = dpu_init,<br>
> + .fini = dpu_fini,<br>
> + .run = dpu_run,<br>
> + .stop = dpu_stop,<br>
> + .isr = dpu_isr,<br>
> + .ifconfig = dpu_dpi_init,<br>
> + .capability = dpu_capability,<br>
> + .flip = dpu_flip,<br>
> + .enable_vsync = enable_vsync,<br>
> + .disable_vsync = disable_vsync,<br>
> +};<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c<br>
> new file mode 100644<br>
> index 0000000..5ec8e7c<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_dpu.c<br>
> @@ -0,0 +1,646 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <linux/component.h><br>
> +#include <linux/dma-buf.h><br>
> +#include <linux/module.h><br>
> +#include <linux/of.h><br>
> +#include <linux/of_address.h><br>
> +#include <linux/of_device.h><br>
> +#include <linux/of_irq.h><br>
> +<br>
> +#include <drm/drm_atomic_helper.h><br>
> +#include <drm/drm_crtc_helper.h><br>
> +#include <drm/drm_fb_cma_helper.h><br>
> +#include <drm/drm_gem_cma_helper.h><br>
> +#include <drm/drm_gem_framebuffer_helper.h><br>
> +#include <drm/drm_plane_helper.h><br>
> +<br>
> +#include "sprd_drm.h"<br>
> +#include "sprd_dpu.h"<br>
> +<br>
> +struct sprd_plane {<br>
> + struct drm_plane plane;<br>
> + u32 index;<br>
> + u32 addr[4];<br>
> + u32 pitch[4];<br>
> + u32 format;<br>
> + u32 rotation;<br>
> + u32 blend_mode;<br>
> +};<br>
> +<br>
> +static void sprd_dpu_init(struct sprd_dpu *dpu);<br>
> +static void sprd_dpu_fini(struct sprd_dpu *dpu);<br>
> +<br>
> +static inline struct sprd_plane *to_sprd_plane(struct drm_plane *plane)<br>
> +{<br>
> + return container_of(plane, struct sprd_plane, plane);<br>
> +}<br>
> +<br>
> +static int sprd_plane_format_convert(u32 fourcc, u32 *format)<br>
> +{<br>
> + switch (fourcc) {<br>
> + case DRM_FORMAT_BGRA8888:<br>
> + /* BGRA8888 -> ARGB8888 */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B3B2B1B0;<br>
> + *format |= BIT_DPU_LAY_FORMAT_ARGB8888;<br>
> + break;<br>
> + case DRM_FORMAT_RGBX8888:<br>
> + case DRM_FORMAT_RGBA8888:<br>
> + /* RGBA8888 -> ABGR8888 */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B3B2B1B0;<br>
> + /* FALLTHRU */<br>
> + case DRM_FORMAT_ABGR8888:<br>
> + /* RB switch */<br>
> + *format |= BIT_DPU_LAY_RB_OR_UV_SWITCH;<br>
> + /* FALLTHRU */<br>
> + case DRM_FORMAT_ARGB8888:<br>
> + *format |= BIT_DPU_LAY_FORMAT_ARGB8888;<br>
> + break;<br>
> + case DRM_FORMAT_XBGR8888:<br>
> + /* RB switch */<br>
> + *format |= BIT_DPU_LAY_RB_OR_UV_SWITCH;<br>
> + /* FALLTHRU */<br>
> + case DRM_FORMAT_XRGB8888:<br>
> + *format |= BIT_DPU_LAY_FORMAT_ARGB8888;<br>
> + break;<br>
> + case DRM_FORMAT_BGR565:<br>
> + /* RB switch */<br>
> + *format |= BIT_DPU_LAY_RB_OR_UV_SWITCH;<br>
> + /* FALLTHRU */<br>
> + case DRM_FORMAT_RGB565:<br>
> + *format |= BIT_DPU_LAY_FORMAT_RGB565;<br>
> + break;<br>
> + case DRM_FORMAT_NV12:<br>
> + /* 2-Lane: Yuv420 */<br>
> + *format |= BIT_DPU_LAY_FORMAT_YUV420_2PLANE;<br>
> + /* Y endian */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B0B1B2B3;<br>
> + /* UV endian */<br>
> + *format |= BIT_DPU_LAY_NO_SWITCH;<br>
> + break;<br>
> + case DRM_FORMAT_NV21:<br>
> + /* 2-Lane: Yuv420 */<br>
> + *format |= BIT_DPU_LAY_FORMAT_YUV420_2PLANE;<br>
> + /* Y endian */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B0B1B2B3;<br>
> + /* UV endian */<br>
> + *format |= BIT_DPU_LAY_RB_OR_UV_SWITCH;<br>
> + break;<br>
> + case DRM_FORMAT_NV16:<br>
> + /* 2-Lane: Yuv422 */<br>
> + *format |= BIT_DPU_LAY_FORMAT_YUV422_2PLANE;<br>
> + /* Y endian */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B3B2B1B0;<br>
> + /* UV endian */<br>
> + *format |= BIT_DPU_LAY_RB_OR_UV_SWITCH;<br>
> + break;<br>
> + case DRM_FORMAT_NV61:<br>
> + /* 2-Lane: Yuv422 */<br>
> + *format |= BIT_DPU_LAY_FORMAT_YUV422_2PLANE;<br>
> + /* Y endian */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B0B1B2B3;<br>
> + /* UV endian */<br>
> + *format |= BIT_DPU_LAY_NO_SWITCH;<br>
> + break;<br>
> + case DRM_FORMAT_YUV420:<br>
> + *format |= BIT_DPU_LAY_FORMAT_YUV420_3PLANE;<br>
> + /* Y endian */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B0B1B2B3;<br>
> + /* UV endian */<br>
> + *format |= BIT_DPU_LAY_NO_SWITCH;<br>
> + break;<br>
> + case DRM_FORMAT_YVU420:<br>
> + *format |= BIT_DPU_LAY_FORMAT_YUV420_3PLANE;<br>
> + /* Y endian */<br>
> + *format |= BIT_DPU_LAY_DATA_ENDIAN_B0B1B2B3;<br>
> + /* UV endian */<br>
> + *format |= BIT_DPU_LAY_RB_OR_UV_SWITCH;<br>
> + break;<br>
> + default:<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_plane_rotation_convert(u32 angle, u32 *rotation)<br>
> +{<br>
> + switch (angle) {<br>
> + case DRM_MODE_ROTATE_0:<br>
> + *rotation = DPU_LAYER_ROTATION_0;<br>
> + break;<br>
> + case DRM_MODE_ROTATE_90:<br>
> + *rotation = DPU_LAYER_ROTATION_90;<br>
> + break;<br>
> + case DRM_MODE_ROTATE_180:<br>
> + *rotation = DPU_LAYER_ROTATION_180;<br>
> + break;<br>
> + case DRM_MODE_ROTATE_270:<br>
> + *rotation = DPU_LAYER_ROTATION_270;<br>
> + break;<br>
> + case DRM_MODE_REFLECT_Y:<br>
> + *rotation = DPU_LAYER_ROTATION_180_M;<br>
> + break;<br>
> + case (DRM_MODE_REFLECT_Y | DRM_MODE_ROTATE_90):<br>
> + *rotation = DPU_LAYER_ROTATION_90_M;<br>
> + break;<br>
> + case DRM_MODE_REFLECT_X:<br>
> + *rotation = DPU_LAYER_ROTATION_0_M;<br>
> + break;<br>
> + case (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90):<br>
> + *rotation = DPU_LAYER_ROTATION_270_M;<br>
> + break;<br>
> + default:<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_plane_atomic_check(struct drm_plane *plane,<br>
> + struct drm_plane_state *state)<br>
> +{<br>
> + struct sprd_plane *p = to_sprd_plane(plane);<br>
> + struct drm_framebuffer *fb = state->fb;<br>
> + struct drm_gem_cma_object *cma_obj;<br>
> + int i, ret;<br>
> + u32 addr;<br>
> +<br>
> + if (!state->fb || !state->crtc)<br>
> + return 0;<br>
> +<br>
> + ret = sprd_plane_format_convert(fb->format->format,<br>
> + &p->format);<br>
> + if (ret < 0) {<br>
> + DRM_ERROR("Invalid plane format\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + ret = sprd_plane_rotation_convert(state->rotation,<br>
> + &p->rotation);<br>
> + if (ret < 0) {<br>
> + DRM_ERROR("Invalid plane rotation\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + switch (state->pixel_blend_mode) {<br>
> + case DRM_MODE_BLEND_COVERAGE:<br>
> + /* alpha mode select - combo alpha */<br>
> + p->blend_mode |= BIT_DPU_LAY_COMBO_ALPHA;<br>
> + /* Normal mode */<br>
> + p->blend_mode |= BIT_DPU_LAY_MODE_BLEND_NORMAL;<br>
> + break;<br>
> + case DRM_MODE_BLEND_PREMULTI:<br>
> + /* alpha mode select - combo alpha */<br>
> + p->blend_mode |= BIT_DPU_LAY_COMBO_ALPHA;<br>
> + /* Pre-mult mode */<br>
> + p->blend_mode |= BIT_DPU_LAY_MODE_BLEND_PREMULT;<br>
> + break;<br>
> + case DRM_MODE_BLEND_PIXEL_NONE:<br>
> + default:<br>
> + /* don't do blending, maybe RGBX */<br>
> + /* alpha mode select - layer alpha */<br>
> + p->blend_mode |= BIT_DPU_LAY_LAYER_ALPHA;<br>
> + break;<br>
> + }<br>
> +<br>
> + for (i = 0; i < fb->format->num_planes; i++) {<br>
> + cma_obj = drm_fb_cma_get_gem_obj(fb, i);<br>
> + addr = cma_obj->paddr + fb->offsets[i];<br>
> + if (addr % 16) {<br>
> + DRM_ERROR("layer addr[%d] is not 16 bytes align, it's 0x%08x\n",<br>
> + i, addr);<br>
> + return -EFAULT;<br>
> + }<br>
> +<br>
> + p->addr[i] = addr;<br>
> + p->pitch[i] = fb->pitches[i];<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_plane_atomic_update(struct drm_plane *plane,<br>
> + struct drm_plane_state *old_state)<br>
> +{<br>
> + struct drm_plane_state *state = plane->state;<br>
> + struct drm_framebuffer *fb = plane->state->fb;<br>
> + struct sprd_plane *p = to_sprd_plane(plane);<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(plane->state->crtc);<br>
> + struct dpu_layer *layer = &dpu->layers[p->index];<br>
> + int i;<br>
> +<br>
> + if (!state->crtc || !state->fb)<br>
> + return;<br>
> +<br>
> + layer->index = p->index;<br>
> + layer->src_x = state->src_x >> 16;<br>
> + layer->src_y = state->src_y >> 16;<br>
> + layer->src_w = state->src_w >> 16;<br>
> + layer->src_h = state->src_h >> 16;<br>
> + layer->dst_x = state->crtc_x;<br>
> + layer->dst_y = state->crtc_y;<br>
> + layer->dst_w = state->crtc_w;<br>
> + layer->dst_h = state->crtc_h;<br>
> + layer->alpha = state->alpha;<br>
> + layer->format = p->format;<br>
> + layer->blending = p->blend_mode;<br>
> + layer->rotation = p->rotation;<br>
> + layer->planes = fb->format->num_planes;<br>
> +<br>
> + for (i = 0; i < layer->planes; i++) {<br>
> + layer->addr[i] = p->addr[i];<br>
> + layer->pitch[i] = p->pitch[i];<br>
> + }<br>
> +<br>
> + dpu->pending_planes++;<br>
> +}<br>
> +<br>
> +static void sprd_plane_create_properties(struct sprd_plane *p, int index)<br>
> +{<br>
> + unsigned int supported_modes = BIT(DRM_MODE_BLEND_PIXEL_NONE) |<br>
> + BIT(DRM_MODE_BLEND_PREMULTI) |<br>
> + BIT(DRM_MODE_BLEND_COVERAGE);<br>
> +<br>
> + /* create rotation property */<br>
> + drm_plane_create_rotation_property(&p->plane,<br>
> + DRM_MODE_ROTATE_0,<br>
> + DRM_MODE_ROTATE_MASK |<br>
> + DRM_MODE_REFLECT_MASK);<br>
> +<br>
> + /* create alpha property */<br>
> + drm_plane_create_alpha_property(&p->plane);<br>
> +<br>
> + /* create blend mode property */<br>
> + drm_plane_create_blend_mode_property(&p->plane, supported_modes);<br>
> +<br>
> + /* create zpos property */<br>
> + drm_plane_create_zpos_immutable_property(&p->plane, index);<br>
> +}<br>
> +<br>
> +static const struct drm_plane_helper_funcs sprd_plane_helper_funcs = {<br>
> + .atomic_check = sprd_plane_atomic_check,<br>
> + .atomic_update = sprd_plane_atomic_update,<br>
> +};<br>
> +<br>
> +static const struct drm_plane_funcs sprd_plane_funcs = {<br>
> + .update_plane = drm_atomic_helper_update_plane,<br>
> + .disable_plane = drm_atomic_helper_disable_plane,<br>
> + .destroy = drm_plane_cleanup,<br>
> + .reset = drm_atomic_helper_plane_reset,<br>
> + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,<br>
> + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,<br>
> +};<br>
> +<br>
> +static struct drm_plane *sprd_plane_init(struct drm_device *drm,<br>
> + struct sprd_dpu *dpu)<br>
> +{<br>
> + struct drm_plane *primary = NULL;<br>
> + struct sprd_plane *p = NULL;<br>
> + struct dpu_capability cap = {};<br>
> + int ret, i;<br>
> +<br>
> + dpu->core->capability(&dpu->ctx, &cap);<br>
> +<br>
> + dpu->layers = devm_kcalloc(drm->dev, cap.max_layers,<br>
> + sizeof(struct dpu_layer), GFP_KERNEL);<br>
> + if (!dpu->layers)<br>
> + return ERR_PTR(-ENOMEM);<br>
> +<br>
> + for (i = 0; i < cap.max_layers; i++) {<br>
> +<br>
> + p = devm_kzalloc(drm->dev, sizeof(*p), GFP_KERNEL);<br>
> + if (!p)<br>
> + return ERR_PTR(-ENOMEM);<br>
> +<br>
> + ret = drm_universal_plane_init(drm, &p->plane, 1,<br>
> + &sprd_plane_funcs, cap.fmts_ptr,<br>
> + cap.fmts_cnt, NULL,<br>
> + DRM_PLANE_TYPE_PRIMARY, NULL);<br>
> + if (ret) {<br>
> + DRM_ERROR("fail to init primary plane\n");<br>
> + return ERR_PTR(ret);<br>
> + }<br>
> +<br>
> + drm_plane_helper_add(&p->plane, &sprd_plane_helper_funcs);<br>
> +<br>
> + sprd_plane_create_properties(p, i);<br>
> +<br>
> + p->index = i;<br>
> + if (i == 0)<br>
> + primary = &p->plane;<br>
> + }<br>
> +<br>
> + return primary;<br>
> +}<br>
> +<br>
> +static enum drm_mode_status sprd_crtc_mode_valid(struct drm_crtc *crtc,<br>
> + const struct drm_display_mode *mode)<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> +<br>
> + DRM_DEBUG("%s() mode: "DRM_MODE_FMT"\n", __func__, DRM_MODE_ARG(mode));<br>
> +<br>
> + if (mode->type & DRM_MODE_TYPE_PREFERRED) {<br>
> + drm_display_mode_to_videomode(mode, &dpu->ctx.vm);<br>
> +<br>
> + if ((mode->hdisplay == mode->htotal) ||<br>
> + (mode->vdisplay == mode->vtotal))<br>
> + dpu->ctx.if_type = SPRD_DPU_IF_EDPI;<br>
> + else<br>
> + dpu->ctx.if_type = SPRD_DPU_IF_DPI;<br>
> + }<br>
> +<br>
> + return MODE_OK;<br>
> +}<br>
> +<br>
> +static void sprd_crtc_atomic_enable(struct drm_crtc *crtc,<br>
> + struct drm_crtc_state *old_state)<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> +<br>
> + sprd_dpu_init(dpu);<br>
> +<br>
> + enable_irq(dpu->ctx.irq);<br>
> +}<br>
> +<br>
> +static void sprd_crtc_atomic_disable(struct drm_crtc *crtc,<br>
> + struct drm_crtc_state *old_state)<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> + struct drm_device *drm = dpu-><a href="http://crtc.dev" rel="noreferrer" target="_blank">crtc.dev</a>;<br>
> +<br>
> + disable_irq(dpu->ctx.irq);<br>
> +<br>
> + sprd_dpu_fini(dpu);<br>
> +<br>
> + spin_lock_irq(&drm->event_lock);<br>
> + if (crtc->state->event) {<br>
> + drm_crtc_send_vblank_event(crtc, crtc->state->event);<br>
> + crtc->state->event = NULL;<br>
> + }<br>
> + spin_unlock_irq(&drm->event_lock);<br>
> +}<br>
> +<br>
> +static int sprd_crtc_atomic_check(struct drm_crtc *crtc,<br>
> + struct drm_crtc_state *state)<br>
> +{<br>
> + DRM_DEBUG("%s()\n", __func__);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_crtc_atomic_begin(struct drm_crtc *crtc,<br>
> + struct drm_crtc_state *old_state)<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> +<br>
> + memset(dpu->layers, 0, sizeof(*dpu->layers) * dpu->pending_planes);<br>
> +<br>
> + dpu->pending_planes = 0;<br>
> +}<br>
> +<br>
> +static void sprd_crtc_atomic_flush(struct drm_crtc *crtc,<br>
> + struct drm_crtc_state *old_state)<br>
> +<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> + struct drm_device *drm = dpu-><a href="http://crtc.dev" rel="noreferrer" target="_blank">crtc.dev</a>;<br>
> +<br>
> + if (dpu->pending_planes)<br>
> + dpu->core->flip(&dpu->ctx, dpu->layers, dpu->pending_planes);<br>
> +<br>
> + spin_lock_irq(&drm->event_lock);<br>
> + if (crtc->state->event) {<br>
> + drm_crtc_send_vblank_event(crtc, crtc->state->event);<br>
> + crtc->state->event = NULL;<br>
> + }<br>
> + spin_unlock_irq(&drm->event_lock);<br>
> +}<br>
> +<br>
> +static int sprd_crtc_enable_vblank(struct drm_crtc *crtc)<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> +<br>
> + dpu->core->enable_vsync(&dpu->ctx);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_crtc_disable_vblank(struct drm_crtc *crtc)<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> +<br>
> + dpu->core->disable_vsync(&dpu->ctx);<br>
> +}<br>
> +<br>
> +static const struct drm_crtc_helper_funcs sprd_crtc_helper_funcs = {<br>
> + .mode_valid = sprd_crtc_mode_valid,<br>
> + .atomic_check = sprd_crtc_atomic_check,<br>
> + .atomic_begin = sprd_crtc_atomic_begin,<br>
> + .atomic_flush = sprd_crtc_atomic_flush,<br>
> + .atomic_enable = sprd_crtc_atomic_enable,<br>
> + .atomic_disable = sprd_crtc_atomic_disable,<br>
> +};<br>
> +<br>
> +static const struct drm_crtc_funcs sprd_crtc_funcs = {<br>
> + .destroy = drm_crtc_cleanup,<br>
> + .set_config = drm_atomic_helper_set_config,<br>
> + .page_flip = drm_atomic_helper_page_flip,<br>
> + .reset = drm_atomic_helper_crtc_reset,<br>
> + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,<br>
> + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,<br>
> + .enable_vblank = sprd_crtc_enable_vblank,<br>
> + .disable_vblank = sprd_crtc_disable_vblank,<br>
> +};<br>
> +<br>
> +static int sprd_crtc_init(struct drm_device *drm, struct drm_crtc *crtc,<br>
> + struct drm_plane *primary)<br>
> +{<br>
> + struct device_node *port;<br>
> + int ret;<br>
> +<br>
> + /*<br>
> + * set crtc port so that drm_of_find_possible_crtcs call works<br>
> + */<br>
> + port = of_parse_phandle(drm->dev->of_node, "ports", 0);<br>
> + if (!port) {<br>
> + DRM_ERROR("find 'ports' phandle of %s failed\n",<br>
> + drm->dev->of_node->full_name);<br>
> + return -EINVAL;<br>
> + }<br>
> + of_node_put(port);<br>
> + crtc->port = port;<br>
> +<br>
> + ret = drm_crtc_init_with_planes(drm, crtc, primary, NULL,<br>
> + &sprd_crtc_funcs, NULL);<br>
> + if (ret) {<br>
> + DRM_ERROR("failed to init crtc.\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + drm_mode_crtc_set_gamma_size(crtc, 256);<br>
> +<br>
> + drm_crtc_helper_add(crtc, &sprd_crtc_helper_funcs);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_dpu_init(struct sprd_dpu *dpu)<br>
> +{<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + dpu->core->init(ctx);<br>
> + dpu->core->ifconfig(ctx);<br>
> +}<br>
> +<br>
> +static void sprd_dpu_fini(struct sprd_dpu *dpu)<br>
> +{<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + dpu->core->fini(ctx);<br>
> +}<br>
> +<br>
> +static irqreturn_t sprd_dpu_isr(int irq, void *data)<br>
> +{<br>
> + struct sprd_dpu *dpu = data;<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> + u32 int_mask = 0;<br>
> +<br>
> + int_mask = dpu->core->isr(ctx);<br>
> +<br>
> + if (int_mask & BIT_DPU_INT_ERR)<br>
> + DRM_WARN("Warning: dpu underflow!\n");<br>
> +<br>
> + if (int_mask & BIT_DPU_INT_VSYNC)<br>
> + drm_crtc_handle_vblank(&dpu->crtc);<br>
> +<br>
> + return IRQ_HANDLED;<br>
> +}<br>
> +<br>
> +static int sprd_dpu_bind(struct device *dev, struct device *master, void *data)<br>
> +{<br>
> + struct drm_device *drm = data;<br>
> + struct sprd_dpu *dpu = dev_get_drvdata(dev);<br>
> + struct drm_plane *plane;<br>
> + int ret;<br>
> +<br>
> + plane = sprd_plane_init(drm, dpu);<br>
> + if (IS_ERR_OR_NULL(plane)) {<br>
> + ret = PTR_ERR(plane);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + ret = sprd_crtc_init(drm, &dpu->crtc, plane);<br>
> + if (ret)<br>
> + return ret;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_dpu_unbind(struct device *dev, struct device *master,<br>
> + void *data)<br>
> +{<br>
> + struct sprd_dpu *dpu = dev_get_drvdata(dev);<br>
> +<br>
> + drm_crtc_cleanup(&dpu->crtc);<br>
> +}<br>
> +<br>
> +static const struct component_ops dpu_component_ops = {<br>
> + .bind = sprd_dpu_bind,<br>
> + .unbind = sprd_dpu_unbind,<br>
> +};<br>
> +<br>
> +static int sprd_dpu_context_init(struct sprd_dpu *dpu,<br>
> + struct device *dev)<br>
> +{<br>
> + struct platform_device *pdev = to_platform_device(dev);<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> + struct resource *res;<br>
> + int ret;<br>
> +<br>
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);<br>
> + ctx->base = devm_ioremap(dev, res->start, resource_size(res));<br>
> + if (!ctx->base) {<br>
> + DRM_ERROR("failed to map dpu registers\n");<br>
> + return -EFAULT;<br>
> + }<br>
> +<br>
> + ctx->irq = platform_get_irq(pdev, 0);<br>
> + if (ctx->irq < 0) {<br>
> + DRM_ERROR("failed to get dpu irq\n");<br>
> + return ctx->irq;<br>
> + }<br>
> +<br>
> + irq_set_status_flags(ctx->irq, IRQ_NOAUTOEN);<br>
> + ret = devm_request_irq(dev, ctx->irq, sprd_dpu_isr,<br>
> + 0, "DPU", dpu);<br>
> + if (ret) {<br>
> + DRM_ERROR("failed to register dpu irq handler\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + init_waitqueue_head(&ctx->wait_queue);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct sprd_dpu_ops sharkl3_dpu = {<br>
> + .core = &dpu_r2p0_core_ops,<br>
> +};<br>
> +<br>
> +static const struct of_device_id dpu_match_table[] = {<br>
> + { .compatible = "sprd,sharkl3-dpu",<br>
> + .data = &sharkl3_dpu },<br>
> + { /* sentinel */ },<br>
> +};<br>
> +<br>
> +static int sprd_dpu_probe(struct platform_device *pdev)<br>
> +{<br>
> + const struct sprd_dpu_ops *pdata;<br>
> + struct sprd_dpu *dpu;<br>
> + int ret;<br>
> +<br>
> + dpu = devm_kzalloc(&pdev->dev, sizeof(*dpu), GFP_KERNEL);<br>
> + if (!dpu)<br>
> + return -ENOMEM;<br>
> +<br>
> + pdata = of_device_get_match_data(&pdev->dev);<br>
> + if (pdata) {<br>
> + dpu->core = pdata->core;<br>
> + } else {<br>
> + DRM_ERROR("No matching driver data found\n");<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + ret = sprd_dpu_context_init(dpu, &pdev->dev);<br>
> + if (ret)<br>
> + return ret;<br>
> +<br>
> + platform_set_drvdata(pdev, dpu);<br>
> +<br>
> + return component_add(&pdev->dev, &dpu_component_ops);<br>
> +}<br>
> +<br>
> +static int sprd_dpu_remove(struct platform_device *pdev)<br>
> +{<br>
> + component_del(&pdev->dev, &dpu_component_ops);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +struct platform_driver sprd_dpu_driver = {<br>
> + .probe = sprd_dpu_probe,<br>
> + .remove = sprd_dpu_remove,<br>
> + .driver = {<br>
> + .name = "sprd-dpu-drv",<br>
> + .of_match_table = dpu_match_table,<br>
> + },<br>
> +};<br>
> +<br>
> +MODULE_AUTHOR("Leon He <<a href="mailto:leon.he@unisoc.com" target="_blank">leon.he@unisoc.com</a>>");<br>
> +MODULE_AUTHOR("Kevin Tang <<a href="mailto:kevin.tang@unisoc.com" target="_blank">kevin.tang@unisoc.com</a>>");<br>
> +MODULE_DESCRIPTION("Unisoc Display Controller Driver");<br>
> +MODULE_LICENSE("GPL v2");<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_dpu.h b/drivers/gpu/drm/sprd/sprd_dpu.h<br>
> new file mode 100644<br>
> index 0000000..7d3c5e4<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_dpu.h<br>
> @@ -0,0 +1,187 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#ifndef __SPRD_DPU_H__<br>
> +#define __SPRD_DPU_H__<br>
> +<br>
> +#include <linux/bug.h><br>
> +#include <linux/delay.h><br>
> +#include <linux/device.h><br>
> +#include <linux/kernel.h><br>
> +#include <linux/platform_device.h><br>
> +#include <linux/string.h><br>
> +#include <video/videomode.h><br>
> +<br>
> +#include <drm/drm_crtc.h><br>
> +#include <drm/drm_fourcc.h><br>
> +#include <drm/drm_print.h><br>
> +#include <drm/drm_vblank.h><br>
> +#include <uapi/drm/drm_mode.h><br>
> +<br>
> +#define BIT_DPU_INT_DONE_ BIT(0)<br>
> +#define BIT_DPU_INT_TE BIT(1)<br>
> +#define BIT_DPU_INT_ERR BIT(2)<br>
> +#define BIT_DPU_INT_EDPI_TE BIT(3)<br>
> +#define BIT_DPU_INT_UPDATE_DONE BIT(4)<br>
> +#define BIT_DPU_INT_VSYNC BIT(5)<br>
> +#define BIT_DPU_INT_WB_DONE BIT(6)<br>
> +#define BIT_DPU_INT_WB_ERR BIT(7)<br>
> +<br>
> +#define BIT_DPU_LAY_LAYER_ALPHA (0x01 << 2)<br>
> +#define BIT_DPU_LAY_COMBO_ALPHA (0x02 << 2)<br>
> +#define BIT_DPU_LAY_FORMAT_YUV422_2PLANE (0x00 << 4)<br>
> +#define BIT_DPU_LAY_FORMAT_YUV420_2PLANE (0x01 << 4)<br>
> +#define BIT_DPU_LAY_FORMAT_YUV420_3PLANE (0x02 << 4)<br>
> +#define BIT_DPU_LAY_FORMAT_ARGB8888 (0x03 << 4)<br>
> +#define BIT_DPU_LAY_FORMAT_RGB565 (0x04 << 4)<br>
> +#define BIT_DPU_LAY_DATA_ENDIAN_B0B1B2B3 (0x00 << 8)<br>
> +#define BIT_DPU_LAY_DATA_ENDIAN_B3B2B1B0 (0x01 << 8)<br>
> +#define BIT_DPU_LAY_NO_SWITCH (0x00 << 10)<br>
> +#define BIT_DPU_LAY_RB_OR_UV_SWITCH (0x01 << 10)<br>
> +#define BIT_DPU_LAY_MODE_BLEND_NORMAL (0x00 << 16)<br>
> +#define BIT_DPU_LAY_MODE_BLEND_PREMULT (0x01 << 16)<br>
> +<br>
> +enum {<br>
> + SPRD_DPU_IF_DBI = 0,<br>
> + SPRD_DPU_IF_DPI,<br>
> + SPRD_DPU_IF_EDPI,<br>
> + SPRD_DPU_IF_LIMIT<br>
> +};<br>
> +<br>
> +enum {<br>
> + DPU_LAYER_ROTATION_0,<br>
> + DPU_LAYER_ROTATION_90,<br>
> + DPU_LAYER_ROTATION_180,<br>
> + DPU_LAYER_ROTATION_270,<br>
> + DPU_LAYER_ROTATION_0_M,<br>
> + DPU_LAYER_ROTATION_90_M,<br>
> + DPU_LAYER_ROTATION_180_M,<br>
> + DPU_LAYER_ROTATION_270_M,<br>
> +};<br>
> +<br>
> +struct dpu_layer {<br>
> + u8 index;<br>
> + u8 planes;<br>
> + u32 addr[4];<br>
> + u32 pitch[4];<br>
> + s16 src_x;<br>
> + s16 src_y;<br>
> + s16 src_w;<br>
> + s16 src_h;<br>
> + s16 dst_x;<br>
> + s16 dst_y;<br>
> + u16 dst_w;<br>
> + u16 dst_h;<br>
> + u32 format;<br>
> + u32 alpha;<br>
> + u32 blending;<br>
> + u32 rotation;<br>
> +};<br>
> +<br>
> +/**<br>
> + * Sprd DPU capability structure<br>
> + *<br>
> + * @max_layers: maximum number of layers available<br>
> + * @fmts_ptr: A pointer to array of supported pixel formats<br>
> + * @fmts_cnt: the number of format on @fmts_ptr<br>
> + */<br>
> +struct dpu_capability {<br>
> + u32 max_layers;<br>
> + const u32 *fmts_ptr;<br>
> + u32 fmts_cnt;<br>
> +};<br>
> +<br>
> +/**<br>
> + * Sprd DPU core callback ops<br>
> + *<br>
> + * This structure decribes the display controller common<br>
> + * callback ops<br>
> + *<br>
> + * @init: initial DPU core<br>
> + * @fini: cleanup DPU core<br>
> + * @run: enable DPU output<br>
> + * @stop: disable DPU output<br>
> + * @enable_vsync: enable vblank interrupt<br>
> + * @disable_vsync: disable vblank interrupt<br>
> + * @isr: function pointer to the isr<br>
> + * @ifconfig: initial DPI interface<br>
> + * @flip: commit CRTC planes to DPU<br>
> + * @capability: callback for DPU capabilities<br>
> + */<br>
> +struct dpu_context;<br>
> +struct dpu_core_ops {<br>
> + void (*init)(struct dpu_context *ctx);<br>
> + void (*fini)(struct dpu_context *ctx);<br>
> + void (*run)(struct dpu_context *ctx);<br>
> + void (*stop)(struct dpu_context *ctx);<br>
> + void (*enable_vsync)(struct dpu_context *ctx);<br>
> + void (*disable_vsync)(struct dpu_context *ctx);<br>
> + u32 (*isr)(struct dpu_context *ctx);<br>
> + void (*ifconfig)(struct dpu_context *ctx);<br>
> + void (*flip)(struct dpu_context *ctx,<br>
> + struct dpu_layer layers[], u8 count);<br>
> + void (*capability)(struct dpu_context *ctx,<br>
> + struct dpu_capability *cap);<br>
> +};<br>
> +<br>
> +/**<br>
> + * Sprd DPU context structure<br>
> + *<br>
> + * @base: DPU controller base address<br>
> + * @irq: IRQ number to install the handler for<br>
> + * @if_type: The type of DPI interface, default is DPI mode.<br>
> + * @vm: videomode structure to use for DPU and DPI initialization<br>
> + * @stopped: indicates whether DPU are stopped<br>
> + * @wait_queue: wait queue, used to wait for DPU shadow register update done and<br>
> + * DPU stop register done interrupt signal.<br>
> + * @evt_update: wait queue condition for DPU shadow register<br>
> + * @evt_stop: wait queue condition for DPU stop register<br>
> + */<br>
> +struct dpu_context {<br>
> + void __iomem *base;<br>
> + int irq;<br>
> + u8 if_type;<br>
> + struct videomode vm;<br>
> + bool stopped;<br>
> + wait_queue_head_t wait_queue;<br>
> + bool evt_update;<br>
> + bool evt_stop;<br>
> +};<br>
> +<br>
> +/**<br>
> + * Sprd DPU device structure<br>
> + *<br>
> + * @crtc: DRM crtc<br>
> + * @ctx: A pointer to the DPU's implementation specific context<br>
> + * @core: pointer to callbacks for DPU core functionality<br>
> + * @layers: active DPU layers ready to commit<br>
> + * @pending_planes: the number of layers on @layers<br>
> + */<br>
> +struct sprd_dpu {<br>
> + struct drm_crtc crtc;<br>
> + struct dpu_context ctx;<br>
> + const struct dpu_core_ops *core;<br>
> + struct dpu_layer *layers;<br>
> + u8 pending_planes;<br>
> +};<br>
> +<br>
> +/**<br>
> + * Sprd DPU H/W callback ops match table structure<br>
> + * The structure used for matching a specific device callback ops<br>
> + *<br>
> + * @core: pointer to callbacks for DPU core functionality<br>
> + */<br>
> +struct sprd_dpu_ops {<br>
> + const struct dpu_core_ops *core;<br>
> +};<br>
> +<br>
> +static inline struct sprd_dpu *crtc_to_dpu(struct drm_crtc *crtc)<br>
> +{<br>
> + return crtc ? container_of(crtc, struct sprd_dpu, crtc) : NULL;<br>
> +}<br>
> +<br>
> +extern const struct dpu_core_ops dpu_r2p0_core_ops;<br>
> +<br>
> +#endif<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_drm.c b/drivers/gpu/drm/sprd/sprd_drm.c<br>
> index 4706185..200020f 100644<br>
> --- a/drivers/gpu/drm/sprd/sprd_drm.c<br>
> +++ b/drivers/gpu/drm/sprd/sprd_drm.c<br>
> @@ -200,6 +200,7 @@ static struct platform_driver sprd_drm_driver = {<br>
><br>
> static struct platform_driver *sprd_drm_drivers[] = {<br>
> &sprd_drm_driver,<br>
> + &sprd_dpu_driver,<br>
> };<br>
><br>
> static int __init sprd_drm_init(void)<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_drm.h b/drivers/gpu/drm/sprd/sprd_drm.h<br>
> index edf0881..3c32f3a 100644<br>
> --- a/drivers/gpu/drm/sprd/sprd_drm.h<br>
> +++ b/drivers/gpu/drm/sprd/sprd_drm.h<br>
> @@ -13,4 +13,6 @@ struct sprd_drm {<br>
> struct drm_device *drm;<br>
> };<br>
><br>
> +extern struct platform_driver sprd_dpu_driver;<br>
> +<br>
> #endif /* _SPRD_DRM_H_ */<br>
> --<br>
> 2.7.4<br>
><br>
<br>
<br>
-- <br>
Daniel Vetter<br>
Software Engineer, Intel Corporation<br>
<a href="http://blog.ffwll.ch" rel="noreferrer" target="_blank">http://blog.ffwll.ch</a><br>
</blockquote></div></div>