<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 10, 2019 at 6:45 PM Thomas Zimmermann <<a href="mailto:tzimmermann@suse.de" target="_blank">tzimmermann@suse.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi<br>
<br>
Am 10.12.19 um 09:36 schrieb Kevin Tang:<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>
> Cc: Orson Zhai <<a href="mailto:orsonzhai@gmail.com" target="_blank">orsonzhai@gmail.com</a>><br>
> Cc: Baolin Wang <<a href="mailto:baolin.wang@linaro.org" target="_blank">baolin.wang@linaro.org</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>
> drivers/gpu/drm/sprd/Makefile | 6 +-<br>
> drivers/gpu/drm/sprd/disp_lib.c | 290 +++++++<br>
> drivers/gpu/drm/sprd/disp_lib.h | 40 +<br>
> drivers/gpu/drm/sprd/dpu/Makefile | 8 +<br>
> drivers/gpu/drm/sprd/dpu/dpu_r2p0.c | 1464 +++++++++++++++++++++++++++++++++++<br>
> drivers/gpu/drm/sprd/sprd_dpu.c | 1152 +++++++++++++++++++++++++++<br>
> drivers/gpu/drm/sprd/sprd_dpu.h | 217 ++++++<br>
> 7 files changed, 3176 insertions(+), 1 deletion(-)<br>
> create mode 100644 drivers/gpu/drm/sprd/disp_lib.c<br>
> create mode 100644 drivers/gpu/drm/sprd/disp_lib.h<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 df0b316..3f188ab 100644<br>
> --- a/drivers/gpu/drm/sprd/Makefile<br>
> +++ b/drivers/gpu/drm/sprd/Makefile<br>
> @@ -5,4 +5,8 @@ ccflags-y += -Iinclude/drm<br>
> subdir-ccflags-y += -I$(src)<br>
> <br>
> obj-y := sprd_drm.o \<br>
> - sprd_gem.o<br>
> \ No newline at end of file<br>
> + sprd_gem.o \<br>
> + sprd_dpu.o<br>
> +<br>
> +obj-y += disp_lib.o<br>
> +obj-y += dpu/<br>
> \ No newline at end of file<br>
> diff --git a/drivers/gpu/drm/sprd/disp_lib.c b/drivers/gpu/drm/sprd/disp_lib.c<br>
> new file mode 100644<br>
> index 0000000..cadd1ad<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/disp_lib.c<br>
> @@ -0,0 +1,290 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2019 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#define pr_fmt(__fmt) "[drm][%20s] "__fmt, __func__<br>
> +<br>
> +#include <linux/device.h><br>
> +#include <linux/libfdt.h><br>
> +#include <linux/module.h><br>
> +#include <linux/of_graph.h><br>
> +#include <linux/of_platform.h><br>
> +#include <linux/slab.h><br>
> +#include <linux/uaccess.h><br>
> +#include <linux/fs.h><br>
> +<br>
> +#include "disp_lib.h"<br>
> +<br>
> +struct bmp_header {<br>
> + u16 magic;<br>
> + u32 size;<br>
> + u32 unused;<br>
> + u32 start;<br>
> +} __attribute__((__packed__));<br>
> +<br>
> +struct dib_header {<br>
> + u32 size;<br>
> + u32 width;<br>
> + u32 height;<br>
> + u16 planes;<br>
> + u16 bpp;<br>
> + u32 compression;<br>
> + u32 data_size;<br>
> + u32 h_res;<br>
> + u32 v_res;<br>
> + u32 colours;<br>
> + u32 important_colours;<br>
> + u32 red_mask;<br>
> + u32 green_mask;<br>
> + u32 blue_mask;<br>
> + u32 alpha_mask;<br>
> + u32 colour_space;<br>
> + u32 unused[12];<br>
> +} __attribute__((__packed__));<br>
> +<br>
> +int str_to_u32_array(const char *p, u32 base, u32 array[])<br>
> +{<br>
> + const char *start = p;<br>
> + char str[12];<br>
> + int length = 0;<br>
> + int i, ret;<br>
> +<br>
> + pr_info("input: %s", p);<br>
> +<br>
> + for (i = 0 ; i < 255; i++) {<br>
> + while (*p == ' ')<br>
> + p++;<br>
> + if (*p == '\0')<br>
> + break;<br>
> + start = p;<br>
> +<br>
> + while ((*p != ' ') && (*p != '\0'))<br>
> + p++;<br>
> +<br>
> + if ((p - start) >= sizeof(str))<br>
> + break;<br>
> +<br>
> + memset(str, 0, sizeof(str));<br>
> + memcpy(str, start, p - start);<br>
> +<br>
> + ret = kstrtou32(str, base, &array[i]);<br>
> + if (ret) {<br>
> + DRM_ERROR("input format error\n");<br>
> + break;<br>
> + }<br>
> +<br>
> + length++;<br>
> + }<br>
> +<br>
> + return length;<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(str_to_u32_array);<br>
> +<br>
> +int load_dtb_to_mem(const char *name, void **blob)<br>
> +{<br>
> + ssize_t ret;<br>
> + u32 count;<br>
> + struct fdt_header dtbhead;<br>
> + loff_t pos = 0;<br>
> + struct file *fdtb;<br>
> +<br>
> +<br>
> + fdtb = filp_open(name, O_RDONLY, 0644);<br>
> + if (IS_ERR(fdtb)) {<br>
> + DRM_ERROR("%s open file error\n", __func__);<br>
> + return PTR_ERR(fdtb);<br>
> + }<br>
> +<br>
> + ret = kernel_read(fdtb, &dtbhead, sizeof(dtbhead), &pos);<br>
> + pos = 0;<br>
> + count = ntohl(dtbhead.totalsize);<br>
> + *blob = kzalloc(count, GFP_KERNEL);<br>
> + if (*blob == NULL) {<br>
> + filp_close(fdtb, NULL);<br>
> + return -ENOMEM;<br>
> + }<br>
> + ret = kernel_read(fdtb, *blob, count, &pos);<br>
> +<br>
> + if (ret != count) {<br>
> + DRM_ERROR("Read to mem fail: ret %zd size%x\n", ret, count);<br>
> + kfree(*blob);<br>
> + *blob = NULL;<br>
> + filp_close(fdtb, NULL);<br>
> + return ret < 0 ? ret : -ENODEV;<br>
> + }<br>
> +<br>
> + filp_close(fdtb, NULL);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(load_dtb_to_mem);<br>
> +<br>
> +int str_to_u8_array(const char *p, u32 base, u8 array[])<br>
> +{<br>
> + const char *start = p;<br>
> + char str[12];<br>
> + int length = 0;<br>
> + int i, ret;<br>
> +<br>
> + pr_info("input: %s", p);<br>
> +<br>
> + for (i = 0 ; i < 255; i++) {<br>
> + while (*p == ' ')<br>
> + p++;<br>
> + if (*p == '\0')<br>
> + break;<br>
> + start = p;<br>
> +<br>
> + while ((*p != ' ') && (*p != '\0'))<br>
> + p++;<br>
> +<br>
> + if ((p - start) >= sizeof(str))<br>
> + break;<br>
> +<br>
> + memset(str, 0, sizeof(str));<br>
> + memcpy(str, start, p - start);<br>
> +<br>
> + ret = kstrtou8(str, base, &array[i]);<br>
> + if (ret) {<br>
> + DRM_ERROR("input format error\n");<br>
> + break;<br>
> + }<br>
> +<br>
> + length++;<br>
> + }<br>
> +<br>
> + return length;<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(str_to_u8_array);<br>
> +<br>
> +int dump_bmp32(const char *p, u32 width, u32 height,<br>
> + bool noflip, const char *filename)<br>
> +{<br>
> + struct file *fp;<br>
> + mm_segment_t fs;<br>
> + loff_t pos;<br>
> + struct dib_header dib_header = {<br>
> + .size = sizeof(dib_header),<br>
> + .width = width,<br>
> + .height = noflip ? -height : height,<br>
> + .planes = 1,<br>
> + .bpp = 32,<br>
> + .compression = 3,<br>
> + .data_size = 4 * width * height,<br>
> + .h_res = 0xB13,<br>
> + .v_res = 0xB13,<br>
> + .colours = 0,<br>
> + .important_colours = 0,<br>
> + .red_mask = 0x000000FF,<br>
> + .green_mask = 0x0000FF00,<br>
> + .blue_mask = 0x00FF0000,<br>
> + .alpha_mask = 0xFF000000,<br>
> + .colour_space = 0x57696E20,<br>
> + };<br>
> + struct bmp_header bmp_header = {<br>
> + .magic = 0x4d42,<br>
> + .size = (width * height * 4) +<br>
> + sizeof(bmp_header) + sizeof(dib_header),<br>
> + .start = sizeof(bmp_header) + sizeof(dib_header),<br>
> + };<br>
> +<br>
> + fp = filp_open(filename, O_RDWR | O_CREAT, 0644);<br>
> + if (IS_ERR(fp)) {<br>
> + DRM_ERROR("failed to open %s: %ld\n", filename, PTR_ERR(fp));<br>
> + return PTR_ERR(fp);<br>
> + }<br>
> +<br>
> + fs = get_fs();<br>
> + set_fs(KERNEL_DS);<br>
> + pos = 0;<br>
> +<br>
> + vfs_write(fp, (const char *)&bmp_header, sizeof(bmp_header), &pos);<br>
> + vfs_write(fp, (const char *)&dib_header, sizeof(dib_header), &pos);<br>
> + vfs_write(fp, p, width * height * 4, &pos);<br>
> +<br>
> + filp_close(fp, NULL);<br>
> + set_fs(fs);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(dump_bmp32);<br>
> +<br>
> +void *disp_ops_attach(const char *str, struct list_head *head)<br>
> +{<br>
> + struct ops_list *list;<br>
> + const char *ver;<br>
> +<br>
> + list_for_each_entry(list, head, head) {<br>
> + ver = list->entry->ver;<br>
> + if (!strcmp(str, ver))<br>
> + return list->entry->ops;<br>
> + }<br>
> +<br>
> + DRM_ERROR("attach disp ops %s failed\n", str);<br>
> + return NULL;<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(disp_ops_attach);<br>
> +<br>
> +int disp_ops_register(struct ops_entry *entry, struct list_head *head)<br>
> +{<br>
> + struct ops_list *list;<br>
> +<br>
> + list = kzalloc(sizeof(struct ops_list), GFP_KERNEL);<br>
> + if (!list)<br>
> + return -ENOMEM;<br>
> +<br>
> + list->entry = entry;<br>
> + list_add(&list->head, head);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(disp_ops_register);<br>
> +<br>
> +struct device *sprd_disp_pipe_get_by_port(struct device *dev, int port)<br>
> +{<br>
> + struct device_node *np = dev->of_node;<br>
> + struct device_node *endpoint;<br>
> + struct device_node *remote_node;<br>
> + struct platform_device *remote_pdev;<br>
> +<br>
> + endpoint = of_graph_get_endpoint_by_regs(np, port, 0);<br>
> + if (!endpoint) {<br>
> + DRM_ERROR("%s/port%d/endpoint0 was not found\n",<br>
> + np->full_name, port);<br>
> + return NULL;<br>
> + }<br>
> +<br>
> + remote_node = of_graph_get_remote_port_parent(endpoint);<br>
> + if (!remote_node) {<br>
> + DRM_ERROR("device node was not found by endpoint0\n");<br>
> + return NULL;<br>
> + }<br>
> +<br>
> + remote_pdev = of_find_device_by_node(remote_node);<br>
> + if (remote_pdev == NULL) {<br>
> + DRM_ERROR("find %s platform device failed\n",<br>
> + remote_node->full_name);<br>
> + return NULL;<br>
> + }<br>
> +<br>
> + return &remote_pdev->dev;<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(sprd_disp_pipe_get_by_port);<br>
> +<br>
> +struct device *sprd_disp_pipe_get_input(struct device *dev)<br>
> +{<br>
> + return sprd_disp_pipe_get_by_port(dev, 1);<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(sprd_disp_pipe_get_input);<br>
> +<br>
> +struct device *sprd_disp_pipe_get_output(struct device *dev)<br>
> +{<br>
> + return sprd_disp_pipe_get_by_port(dev, 0);<br>
> +}<br>
> +EXPORT_SYMBOL_GPL(sprd_disp_pipe_get_output);<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 common API library");<br>
> +MODULE_LICENSE("GPL");<br>
> diff --git a/drivers/gpu/drm/sprd/disp_lib.h b/drivers/gpu/drm/sprd/disp_lib.h<br>
> new file mode 100644<br>
> index 0000000..7900b89<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/disp_lib.h<br>
> @@ -0,0 +1,40 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2019 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#ifndef _DISP_LIB_H_<br>
> +#define _DISP_LIB_H_<br>
> +<br>
> +#include <linux/list.h><br>
> +#include <drm/drm_print.h><br>
> +<br>
> +#ifdef pr_fmt<br>
> +#undef pr_fmt<br>
> +#define pr_fmt(__fmt) "[drm][%20s] "__fmt, __func__<br>
> +#endif<br>
> +<br>
> +struct ops_entry {<br>
> + const char *ver;<br>
> + void *ops;<br>
> +};<br>
> +<br>
> +struct ops_list {<br>
> + struct list_head head;<br>
> + struct ops_entry *entry;<br>
> +};<br>
> +<br>
> +int str_to_u32_array(const char *p, u32 base, u32 array[]);<br>
> +int str_to_u8_array(const char *p, u32 base, u8 array[]);<br>
> +int dump_bmp32(const char *p, u32 width, u32 height,<br>
> + bool bgra, const char *filename);<br>
> +int load_dtb_to_mem(const char *name, void **blob);<br>
<br>
The bitmap-loading code seems out of place in a driver. It should be a<br>
helper. And efifb has similar code already. Is there an opportunity to<br>
share the implementation?<br>
<br>
I cannot find any caller of load_dtb_to_mem(). Where is it being used?<br>
<br>
Best regards<br>
Thomas<br>
<br>
> +<br>
> +void *disp_ops_attach(const char *str, struct list_head *head);<br>
> +int disp_ops_register(struct ops_entry *entry, struct list_head *head);<br>
> +<br>
> +struct device *sprd_disp_pipe_get_by_port(struct device *dev, int port);<br>
> +struct device *sprd_disp_pipe_get_input(struct device *dev);<br>
> +struct device *sprd_disp_pipe_get_output(struct device *dev);<br>
> +<br>
> +#endif<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..d960107<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dpu/Makefile<br>
> @@ -0,0 +1,8 @@<br>
> +# SPDX-License-Identifier: GPL-2.0<br>
> +<br>
> +ifdef CONFIG_ARM64<br>
> +KBUILD_CFLAGS += -mstrict-align<br>
> +endif<br>
> +<br>
> +obj-y += dpu_r2p0.o<br>
> +<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..4c0a539<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dpu/dpu_r2p0.c<br>
> @@ -0,0 +1,1464 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2019 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <linux/delay.h><br>
> +#include <linux/wait.h><br>
> +#include <linux/workqueue.h><br>
> +#include "sprd_dpu.h"<br>
> +<br>
> +#define DISPC_INT_FBC_PLD_ERR_MASK BIT(8)<br>
> +#define DISPC_INT_FBC_HDR_ERR_MASK BIT(9)<br>
> +<br>
> +#define DISPC_INT_MMU_INV_WR_MASK BIT(19)<br>
> +#define DISPC_INT_MMU_INV_RD_MASK BIT(18)<br>
> +#define DISPC_INT_MMU_VAOR_WR_MASK BIT(17)<br>
> +#define DISPC_INT_MMU_VAOR_RD_MASK BIT(16)<br>
> +<br>
> +#define XFBC8888_HEADER_SIZE(w, h) (ALIGN((w) * (h) / (8 * 8) / 2, 128))<br>
> +#define XFBC8888_PAYLOAD_SIZE(w, h) (w * h * 4)<br>
> +#define XFBC8888_BUFFER_SIZE(w, h) (XFBC8888_HEADER_SIZE(w, h) \<br>
> + + XFBC8888_PAYLOAD_SIZE(w, h))<br>
> +<br>
> +#define XFBC565_HEADER_SIZE(w, h) (ALIGN((w) * (h) / (16 * 8) / 2, 128))<br>
> +#define XFBC565_PAYLOAD_SIZE(w, h) (w * h * 2)<br>
> +#define XFBC565_BUFFER_SIZE(w, h) (XFBC565_HEADER_SIZE(w, h) \<br>
> + + XFBC565_PAYLOAD_SIZE(w, h))<br>
> +<br>
> +#define SLP_BRIGHTNESS_THRESHOLD 0x20<br>
> +<br>
> +struct layer_reg {<br>
> + u32 addr[4];<br>
> + u32 ctrl;<br>
> + u32 size;<br>
> + u32 pitch;<br>
> + u32 pos;<br>
> + u32 alpha;<br>
> + u32 ck;<br>
> + u32 pallete;<br>
> + u32 crop_start;<br>
> +};<br>
> +<br>
> +struct wb_region_reg {<br>
> + u32 pos;<br>
> + u32 size;<br>
> +};<br>
> +<br>
> +struct dpu_reg {<br>
> + u32 dpu_version;<br>
> + u32 dpu_ctrl;<br>
> + u32 dpu_cfg0;<br>
> + u32 dpu_cfg1;<br>
> + u32 dpu_cfg2;<br>
> + u32 dpu_secure;<br>
> + u32 reserved_0x0018_0x001C[2];<br>
> + u32 panel_size;<br>
> + u32 blend_size;<br>
> + u32 reserved_0x0028;<br>
> + u32 bg_color;<br>
> + struct layer_reg layers[8];<br>
> + u32 wb_base_addr;<br>
> + u32 wb_ctrl;<br>
> + u32 wb_cfg;<br>
> + u32 wb_pitch;<br>
> + struct wb_region_reg region[3];<br>
> + u32 reserved_0x01D8_0x01DC[2];<br>
> + u32 dpu_int_en;<br>
> + u32 dpu_int_clr;<br>
> + u32 dpu_int_sts;<br>
> + u32 dpu_int_raw;<br>
> + u32 dpi_ctrl;<br>
> + u32 dpi_h_timing;<br>
> + u32 dpi_v_timing;<br>
> + u32 reserved_0x01FC;<br>
> + u32 dpu_enhance_cfg;<br>
> + u32 reserved_0x0204_0x020C[3];<br>
> + u32 epf_epsilon;<br>
> + u32 epf_gain0_3;<br>
> + u32 epf_gain4_7;<br>
> + u32 epf_diff;<br>
> + u32 reserved_0x0220_0x023C[8];<br>
> + u32 hsv_lut_addr;<br>
> + u32 hsv_lut_wdata;<br>
> + u32 hsv_lut_rdata;<br>
> + u32 reserved_0x024C_0x027C[13];<br>
> + u32 cm_coef01_00;<br>
> + u32 cm_coef03_02;<br>
> + u32 cm_coef11_10;<br>
> + u32 cm_coef13_12;<br>
> + u32 cm_coef21_20;<br>
> + u32 cm_coef23_22;<br>
> + u32 reserved_0x0298_0x02BC[10];<br>
> + u32 slp_cfg0;<br>
> + u32 slp_cfg1;<br>
> + u32 reserved_0x02C8_0x02FC[14];<br>
> + u32 gamma_lut_addr;<br>
> + u32 gamma_lut_wdata;<br>
> + u32 gamma_lut_rdata;<br>
> + u32 reserved_0x030C_0x033C[13];<br>
> + u32 checksum_en;<br>
> + u32 checksum0_start_pos;<br>
> + u32 checksum0_end_pos;<br>
> + u32 checksum1_start_pos;<br>
> + u32 checksum1_end_pos;<br>
> + u32 checksum0_result;<br>
> + u32 checksum1_result;<br>
> + u32 reserved_0x035C;<br>
> + u32 dpu_sts[18];<br>
> + u32 reserved_0x03A8_0x03AC[2];<br>
> + u32 dpu_fbc_cfg0;<br>
> + u32 dpu_fbc_cfg1;<br>
> + u32 reserved_0x03B8_0x03EC[14];<br>
> + u32 rf_ram_addr;<br>
> + u32 rf_ram_rdata_low;<br>
> + u32 rf_ram_rdata_high;<br>
> + u32 reserved_0x03FC_0x07FC[257];<br>
> + u32 mmu_en;<br>
> + u32 mmu_update;<br>
> + u32 mmu_min_vpn;<br>
> + u32 mmu_vpn_range;<br>
> + u32 mmu_pt_addr;<br>
> + u32 mmu_default_page;<br>
> + u32 mmu_vaor_addr_rd;<br>
> + u32 mmu_vaor_addr_wr;<br>
> + u32 mmu_inv_addr_rd;<br>
> + u32 mmu_inv_addr_wr;<br>
> + u32 mmu_uns_addr_rd;<br>
> + u32 mmu_uns_addr_wr;<br>
> + u32 mmu_miss_cnt;<br>
> + u32 mmu_pt_update_qos;<br>
> + u32 mmu_version;<br>
> + u32 mmu_min_ppn1;<br>
> + u32 mmu_ppn_range1;<br>
> + u32 mmu_min_ppn2;<br>
> + u32 mmu_ppn_range2;<br>
> + u32 mmu_vpn_paor_rd;<br>
> + u32 mmu_vpn_paor_wr;<br>
> + u32 mmu_ppn_paor_rd;<br>
> + u32 mmu_ppn_paor_wr;<br>
> + u32 mmu_reg_au_manage;<br>
> + u32 mmu_page_rd_ch;<br>
> + u32 mmu_page_wr_ch;<br>
> + u32 mmu_read_page_cmd_cnt;<br>
> + u32 mmu_read_page_latency_cnt;<br>
> + u32 mmu_page_max_latency;<br>
> +};<br>
> +<br>
> +struct wb_region {<br>
> + u32 index;<br>
> + u16 pos_x;<br>
> + u16 pos_y;<br>
> + u16 size_w;<br>
> + u16 size_h;<br>
> +};<br>
> +<br>
> +struct enhance_module {<br>
> + u32 scl_en: 1;<br>
> + u32 epf_en: 1;<br>
> + u32 hsv_en: 1;<br>
> + u32 cm_en: 1;<br>
> + u32 slp_en: 1;<br>
> + u32 gamma_en: 1;<br>
> + u32 blp_en: 1;<br>
> +};<br>
> +<br>
> +struct scale_cfg {<br>
> + u32 in_w;<br>
> + u32 in_h;<br>
> +};<br>
> +<br>
> +struct epf_cfg {<br>
> + u16 epsilon0;<br>
> + u16 epsilon1;<br>
> + u8 gain0;<br>
> + u8 gain1;<br>
> + u8 gain2;<br>
> + u8 gain3;<br>
> + u8 gain4;<br>
> + u8 gain5;<br>
> + u8 gain6;<br>
> + u8 gain7;<br>
> + u8 max_diff;<br>
> + u8 min_diff;<br>
> +};<br>
> +<br>
> +struct hsv_entry {<br>
> + u16 hue;<br>
> + u16 sat;<br>
> +};<br>
> +<br>
> +struct hsv_lut {<br>
> + struct hsv_entry table[360];<br>
> +};<br>
> +<br>
> +struct gamma_entry {<br>
> + u16 r;<br>
> + u16 g;<br>
> + u16 b;<br>
> +};<br>
> +<br>
> +struct gamma_lut {<br>
> + u16 r[256];<br>
> + u16 g[256];<br>
> + u16 b[256];<br>
> +};<br>
> +<br>
> +struct cm_cfg {<br>
> + short coef00;<br>
> + short coef01;<br>
> + short coef02;<br>
> + short coef03;<br>
> + short coef10;<br>
> + short coef11;<br>
> + short coef12;<br>
> + short coef13;<br>
> + short coef20;<br>
> + short coef21;<br>
> + short coef22;<br>
> + short coef23;<br>
> +};<br>
> +<br>
> +struct slp_cfg {<br>
> + u8 brightness;<br>
> + u8 conversion_matrix;<br>
> + u8 brightness_step;<br>
> + u8 second_bright_factor;<br>
> + u8 first_percent_th;<br>
> + u8 first_max_bright_th;<br>
> +};<br>
> +<br>
> +static struct scale_cfg scale_copy;<br>
> +static struct cm_cfg cm_copy;<br>
> +static struct slp_cfg slp_copy;<br>
> +static struct gamma_lut gamma_copy;<br>
> +static struct hsv_lut hsv_copy;<br>
> +static struct epf_cfg epf_copy;<br>
> +static u32 enhance_en;<br>
> +<br>
> +static DECLARE_WAIT_QUEUE_HEAD(wait_queue);<br>
> +static bool panel_ready = true;<br>
> +static bool need_scale;<br>
> +static bool mode_changed;<br>
> +static bool evt_update;<br>
> +static bool evt_stop;<br>
> +static u32 prev_y2r_coef;<br>
> +<br>
> +static void dpu_sr_config(struct dpu_context *ctx);<br>
> +static void dpu_enhance_reload(struct dpu_context *ctx);<br>
> +static void dpu_clean_all(struct dpu_context *ctx);<br>
> +static void dpu_layer(struct dpu_context *ctx,<br>
> + struct sprd_dpu_layer *hwlayer);<br>
> +<br>
> +static u32 dpu_get_version(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + return reg->dpu_version;<br>
> +}<br>
> +<br>
> +static bool dpu_check_raw_int(struct dpu_context *ctx, u32 mask)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + u32 val;<br>
> +<br>
> + down(&ctx->refresh_lock);<br>
> + if (!ctx->is_inited) {<br>
> + up(&ctx->refresh_lock);<br>
> + pr_err("dpu is not initialized\n");<br>
> + return false;<br>
> + }<br>
> +<br>
> + val = reg->dpu_int_raw;<br>
> + up(&ctx->refresh_lock);<br>
> +<br>
> + if (val & mask)<br>
> + return true;<br>
> +<br>
> + pr_err("dpu_int_raw:0x%x\n", val);<br>
> + return false;<br>
> +}<br>
> +<br>
> +static int dpu_parse_dt(struct dpu_context *ctx,<br>
> + struct device_node *np)<br>
> +{<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void dpu_dump(struct dpu_context *ctx)<br>
> +{<br>
> + u32 *reg = (u32 *)ctx->base;<br>
> + int i;<br>
> +<br>
> + pr_info(" 0 4 8 C\n");<br>
> + for (i = 0; i < 256; i += 4) {<br>
> + pr_info("%04x: 0x%08x 0x%08x 0x%08x 0x%08x\n",<br>
> + i * 4, reg[i], reg[i + 1], reg[i + 2], reg[i + 3]);<br>
> + }<br>
> +}<br>
> +<br>
> +static u32 check_mmu_isr(struct dpu_context *ctx, u32 reg_val)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + u32 mmu_mask = DISPC_INT_MMU_VAOR_RD_MASK |<br>
> + DISPC_INT_MMU_VAOR_WR_MASK |<br>
> + DISPC_INT_MMU_INV_RD_MASK |<br>
> + DISPC_INT_MMU_INV_WR_MASK;<br>
> + u32 val = reg_val & mmu_mask;<br>
> +<br>
> + if (val) {<br>
> + pr_err("--- iommu interrupt err: 0x%04x ---\n", val);<br>
> +<br>
> + pr_err("iommu invalid read error, addr: 0x%08x\n",<br>
> + reg->mmu_inv_addr_rd);<br>
> + pr_err("iommu invalid write error, addr: 0x%08x\n",<br>
> + reg->mmu_inv_addr_wr);<br>
> + pr_err("iommu va out of range read error, addr: 0x%08x\n",<br>
> + reg->mmu_vaor_addr_rd);<br>
> + pr_err("iommu va out of range write error, addr: 0x%08x\n",<br>
> + reg->mmu_vaor_addr_wr);<br>
> + pr_err("BUG: iommu failure at %s:%d/%s()!\n",<br>
> + __FILE__, __LINE__, __func__);<br>
> +<br>
> + dpu_dump(ctx);<br>
> + }<br>
> +<br>
> + return val;<br>
> +}<br>
> +<br>
> +static u32 dpu_isr(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + u32 reg_val, int_mask = 0;<br>
> +<br>
> + reg_val = reg->dpu_int_sts;<br>
> +<br>
> + /* disable err interrupt */<br>
> + if (reg_val & DISPC_INT_ERR_MASK)<br>
> + int_mask |= DISPC_INT_ERR_MASK;<br>
> +<br>
> + /* dpu update done isr */<br>
> + if (reg_val & DISPC_INT_UPDATE_DONE_MASK) {<br>
> + evt_update = true;<br>
> + wake_up_interruptible_all(&wait_queue);<br>
> + }<br>
> +<br>
> + /* dpu stop done isr */<br>
> + if (reg_val & DISPC_INT_DONE_MASK) {<br>
> + evt_stop = true;<br>
> + wake_up_interruptible_all(&wait_queue);<br>
> + }<br>
> +<br>
> + /* dpu ifbc payload error isr */<br>
> + if (reg_val & DISPC_INT_FBC_PLD_ERR_MASK) {<br>
> + int_mask |= DISPC_INT_FBC_PLD_ERR_MASK;<br>
> + pr_err("dpu ifbc payload error\n");<br>
> + }<br>
> +<br>
> + /* dpu ifbc header error isr */<br>
> + if (reg_val & DISPC_INT_FBC_HDR_ERR_MASK) {<br>
> + int_mask |= DISPC_INT_FBC_HDR_ERR_MASK;<br>
> + pr_err("dpu ifbc header error\n");<br>
> + }<br>
> +<br>
> + int_mask |= check_mmu_isr(ctx, reg_val);<br>
> +<br>
> + reg->dpu_int_clr = reg_val;<br>
> + 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->is_stopped)<br>
> + return 0;<br>
> +<br>
> + rc = wait_event_interruptible_timeout(wait_queue, evt_stop,<br>
> + msecs_to_jiffies(500));<br>
> + evt_stop = false;<br>
> +<br>
> + ctx->is_stopped = true;<br>
> +<br>
> + if (!rc) {<br>
> + pr_err("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>
> + evt_update = false;<br>
> +<br>
> + rc = wait_event_interruptible_timeout(wait_queue, evt_update,<br>
> + msecs_to_jiffies(500));<br>
> +<br>
> + if (!rc) {<br>
> + pr_err("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>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + if (ctx->if_type == SPRD_DISPC_IF_DPI)<br>
> + reg->dpu_ctrl |= BIT(1);<br>
> +<br>
> + dpu_wait_stop_done(ctx);<br>
> + pr_info("dpu stop\n");<br>
> +}<br>
> +<br>
> +static void dpu_run(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + reg->dpu_ctrl |= BIT(0);<br>
> +<br>
> + ctx->is_stopped = false;<br>
> +<br>
> + pr_info("dpu run\n");<br>
> +<br>
> + if (ctx->if_type == SPRD_DISPC_IF_EDPI) {<br>
> + /*<br>
> + * If the panel read GRAM speed faster than<br>
> + * DSI write GRAM speed, it will display some<br>
> + * mass on screen when backlight on. So wait<br>
> + * a TE period after flush the GRAM.<br>
> + */<br>
> + if (!panel_ready) {<br>
> + dpu_wait_stop_done(ctx);<br>
> + /* wait for TE again */<br>
> + mdelay(20);<br>
> + panel_ready = true;<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +static int dpu_init(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + u32 size;<br>
> +<br>
> + reg->bg_color = 0;<br>
> +<br>
> + size = (ctx->vm.vactive << 16) | ctx->vm.hactive;<br>
> + reg->panel_size = size;<br>
> + reg->blend_size = size;<br>
> +<br>
> + reg->dpu_cfg0 = BIT(4) | BIT(5);<br>
> + prev_y2r_coef = 3;<br>
> +<br>
> + reg->dpu_cfg1 = 0x004466da;<br>
> + reg->dpu_cfg2 = 0;<br>
> +<br>
> + if (ctx->is_stopped)<br>
> + dpu_clean_all(ctx);<br>
> +<br>
> + reg->mmu_en = 0;<br>
> + reg->mmu_min_ppn1 = 0;<br>
> + reg->mmu_ppn_range1 = 0xffff;<br>
> + reg->mmu_min_ppn2 = 0;<br>
> + reg->mmu_ppn_range2 = 0xffff;<br>
> + reg->mmu_vpn_range = 0x1ffff;<br>
> +<br>
> + reg->dpu_int_clr = 0xffff;<br>
> +<br>
> + dpu_enhance_reload(ctx);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void dpu_uninit(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + reg->dpu_int_en = 0;<br>
> + reg->dpu_int_clr = 0xff;<br>
> +<br>
> + panel_ready = false;<br>
> +}<br>
> +<br>
> +enum {<br>
> + DPU_LAYER_FORMAT_YUV422_2PLANE,<br>
> + DPU_LAYER_FORMAT_YUV420_2PLANE,<br>
> + DPU_LAYER_FORMAT_YUV420_3PLANE,<br>
> + DPU_LAYER_FORMAT_ARGB8888,<br>
> + DPU_LAYER_FORMAT_RGB565,<br>
> + DPU_LAYER_FORMAT_XFBC_ARGB8888 = 8,<br>
> + DPU_LAYER_FORMAT_XFBC_RGB565,<br>
> + DPU_LAYER_FORMAT_MAX_TYPES,<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>
> +static u32 to_dpu_rotation(u32 angle)<br>
> +{<br>
> + u32 rot = DPU_LAYER_ROTATION_0;<br>
> +<br>
> + switch (angle) {<br>
> + case 0:<br>
> + case DRM_MODE_ROTATE_0:<br>
> + rot = DPU_LAYER_ROTATION_0;<br>
> + break;<br>
> + case DRM_MODE_ROTATE_90:<br>
> + rot = DPU_LAYER_ROTATION_90;<br>
> + break;<br>
> + case DRM_MODE_ROTATE_180:<br>
> + rot = DPU_LAYER_ROTATION_180;<br>
> + break;<br>
> + case DRM_MODE_ROTATE_270:<br>
> + rot = DPU_LAYER_ROTATION_270;<br>
> + break;<br>
> + case DRM_MODE_REFLECT_Y:<br>
> + rot = DPU_LAYER_ROTATION_180_M;<br>
> + break;<br>
> + case (DRM_MODE_REFLECT_Y | DRM_MODE_ROTATE_90):<br>
> + rot = DPU_LAYER_ROTATION_90_M;<br>
> + break;<br>
> + case DRM_MODE_REFLECT_X:<br>
> + rot = DPU_LAYER_ROTATION_0_M;<br>
> + break;<br>
> + case (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90):<br>
> + rot = DPU_LAYER_ROTATION_270_M;<br>
> + break;<br>
> + default:<br>
> + pr_err("rotation convert unsupport angle (drm)= 0x%x\n", angle);<br>
> + break;<br>
> + }<br>
> +<br>
> + return rot;<br>
> +}<br>
> +<br>
> +static u32 dpu_img_ctrl(u32 format, u32 blending, u32 compression, u32 rotation)<br>
> +{<br>
> + int reg_val = 0;<br>
> +<br>
> + /* layer enable */<br>
> + reg_val |= BIT(0);<br>
> +<br>
> + switch (format) {<br>
> + case DRM_FORMAT_BGRA8888:<br>
> + /* BGRA8888 -> ARGB8888 */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B3B2B1B0 << 8;<br>
> + if (compression)<br>
> + /* XFBC-ARGB8888 */<br>
> + reg_val |= (DPU_LAYER_FORMAT_XFBC_ARGB8888 << 4);<br>
> + else<br>
> + reg_val |= (DPU_LAYER_FORMAT_ARGB8888 << 4);<br>
> + break;<br>
> + case DRM_FORMAT_RGBX8888:<br>
> + case DRM_FORMAT_RGBA8888:<br>
> + /* RGBA8888 -> ABGR8888 */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B3B2B1B0 << 8;<br>
> + case DRM_FORMAT_ABGR8888:<br>
> + /* rb switch */<br>
> + reg_val |= BIT(10);<br>
> + case DRM_FORMAT_ARGB8888:<br>
> + if (compression)<br>
> + /* XFBC-ARGB8888 */<br>
> + reg_val |= (DPU_LAYER_FORMAT_XFBC_ARGB8888 << 4);<br>
> + else<br>
> + reg_val |= (DPU_LAYER_FORMAT_ARGB8888 << 4);<br>
> + break;<br>
> + case DRM_FORMAT_XBGR8888:<br>
> + /* rb switch */<br>
> + reg_val |= BIT(10);<br>
> + case DRM_FORMAT_XRGB8888:<br>
> + if (compression)<br>
> + /* XFBC-ARGB8888 */<br>
> + reg_val |= (DPU_LAYER_FORMAT_XFBC_ARGB8888 << 4);<br>
> + else<br>
> + reg_val |= (DPU_LAYER_FORMAT_ARGB8888 << 4);<br>
> + break;<br>
> + case DRM_FORMAT_BGR565:<br>
> + /* rb switch */<br>
> + reg_val |= BIT(10);<br>
> + case DRM_FORMAT_RGB565:<br>
> + if (compression)<br>
> + /* XFBC-RGB565 */<br>
> + reg_val |= (DPU_LAYER_FORMAT_XFBC_RGB565 << 4);<br>
> + else<br>
> + reg_val |= (DPU_LAYER_FORMAT_RGB565 << 4);<br>
> + break;<br>
> + case DRM_FORMAT_NV12:<br>
> + /* 2-Lane: Yuv420 */<br>
> + reg_val |= DPU_LAYER_FORMAT_YUV420_2PLANE << 4;<br>
> + /* Y endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 8;<br>
> + /* UV endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 10;<br>
> + break;<br>
> + case DRM_FORMAT_NV21:<br>
> + /* 2-Lane: Yuv420 */<br>
> + reg_val |= DPU_LAYER_FORMAT_YUV420_2PLANE << 4;<br>
> + /* Y endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 8;<br>
> + /* UV endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B3B2B1B0 << 10;<br>
> + break;<br>
> + case DRM_FORMAT_NV16:<br>
> + /* 2-Lane: Yuv422 */<br>
> + reg_val |= DPU_LAYER_FORMAT_YUV422_2PLANE << 4;<br>
> + /* Y endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B3B2B1B0 << 8;<br>
> + /* UV endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B3B2B1B0 << 10;<br>
> + break;<br>
> + case DRM_FORMAT_NV61:<br>
> + /* 2-Lane: Yuv422 */<br>
> + reg_val |= DPU_LAYER_FORMAT_YUV422_2PLANE << 4;<br>
> + /* Y endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 8;<br>
> + /* UV endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 10;<br>
> + break;<br>
> + case DRM_FORMAT_YUV420:<br>
> + reg_val |= DPU_LAYER_FORMAT_YUV420_3PLANE << 4;<br>
> + /* Y endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 8;<br>
> + /* UV endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 10;<br>
> + break;<br>
> + case DRM_FORMAT_YVU420:<br>
> + reg_val |= DPU_LAYER_FORMAT_YUV420_3PLANE << 4;<br>
> + /* Y endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B0B1B2B3 << 8;<br>
> + /* UV endian */<br>
> + reg_val |= SPRD_IMG_DATA_ENDIAN_B3B2B1B0 << 10;<br>
> + break;<br>
> + default:<br>
> + pr_err("error: invalid format %c%c%c%c\n", format,<br>
> + format >> 8,<br>
> + format >> 16,<br>
> + format >> 24);<br>
> + break;<br>
> + }<br>
> +<br>
> + switch (blending) {<br>
> + case DRM_MODE_BLEND_PIXEL_NONE:<br>
> + /* don't do blending, maybe RGBX */<br>
> + /* alpha mode select - layer alpha */<br>
> + reg_val |= BIT(2);<br>
> + break;<br>
> + case DRM_MODE_BLEND_COVERAGE:<br>
> + /* alpha mode select - combo alpha */<br>
> + reg_val |= BIT(3);<br>
> + /*Normal mode*/<br>
> + reg_val &= (~BIT(16));<br>
> + break;<br>
> + case DRM_MODE_BLEND_PREMULTI:<br>
> + /* alpha mode select - combo alpha */<br>
> + reg_val |= BIT(3);<br>
> + /*Pre-mult mode*/<br>
> + reg_val |= BIT(16);<br>
> + break;<br>
> + default:<br>
> + /* alpha mode select - layer alpha */<br>
> + reg_val |= BIT(2);<br>
> + break;<br>
> + }<br>
> +<br>
> + rotation = to_dpu_rotation(rotation);<br>
> + reg_val |= (rotation & 0x7) << 20;<br>
> +<br>
> + return reg_val;<br>
> +}<br>
> +<br>
> +static int check_layer_y2r_coef(struct sprd_dpu_layer layers[], u8 count)<br>
> +{<br>
> + int i;<br>
> +<br>
> + for (i = (count - 1); i >= 0; i--) {<br>
> + switch (layers[i].format) {<br>
> + case DRM_FORMAT_NV12:<br>
> + case DRM_FORMAT_NV21:<br>
> + case DRM_FORMAT_NV16:<br>
> + case DRM_FORMAT_NV61:<br>
> + case DRM_FORMAT_YUV420:<br>
> + case DRM_FORMAT_YVU420:<br>
> + if (layers[i].y2r_coef == prev_y2r_coef)<br>
> + return -EINVAL;<br>
> +<br>
> + /* need to config dpu y2r coef */<br>
> + prev_y2r_coef = layers[i].y2r_coef;<br>
> + return prev_y2r_coef;<br>
> + default:<br>
> + break;<br>
> + }<br>
> + }<br>
> +<br>
> + /* not find yuv layer */<br>
> + return -EINVAL;<br>
> +}<br>
> +<br>
> +static void dpu_clean_all(struct dpu_context *ctx)<br>
> +{<br>
> + int i;<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + for (i = 0; i < 8; i++)<br>
> + reg->layers[i].ctrl = 0;<br>
> +}<br>
> +<br>
> +static void dpu_bgcolor(struct dpu_context *ctx, u32 color)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + if (ctx->if_type == SPRD_DISPC_IF_EDPI)<br>
> + dpu_wait_stop_done(ctx);<br>
> +<br>
> + reg->bg_color = color;<br>
> +<br>
> + dpu_clean_all(ctx);<br>
> +<br>
> + if ((ctx->if_type == SPRD_DISPC_IF_DPI) && !ctx->is_stopped) {<br>
> + reg->dpu_ctrl |= BIT(2);<br>
> + dpu_wait_update_done(ctx);<br>
> + } else if (ctx->if_type == SPRD_DISPC_IF_EDPI) {<br>
> + reg->dpu_ctrl |= BIT(0);<br>
> + ctx->is_stopped = false;<br>
> + }<br>
> +}<br>
> +<br>
> +static void dpu_layer(struct dpu_context *ctx,<br>
> + struct sprd_dpu_layer *hwlayer)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + const struct drm_format_info *info;<br>
> + struct layer_reg *layer;<br>
> + u32 addr, size, offset;<br>
> + int i;<br>
> +<br>
> + layer = ®->layers[hwlayer->index];<br>
> + offset = (hwlayer->dst_x & 0xffff) | ((hwlayer->dst_y) << 16);<br>
> +<br>
> + if (hwlayer->pallete_en) {<br>
> + size = (hwlayer->dst_w & 0xffff) | ((hwlayer->dst_h) << 16);<br>
> + layer->pos = offset;<br>
> + layer->size = size;<br>
> + layer->alpha = hwlayer->alpha;<br>
> + layer->pallete = hwlayer->pallete_color;<br>
> +<br>
> + /* pallete layer enable */<br>
> + layer->ctrl = 0x1005;<br>
> +<br>
> + pr_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>
> + return;<br>
> + }<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>
> + addr = hwlayer->addr[i];<br>
> +<br>
> + /* dpu r2p0 just support xfbc-rgb */<br>
> + if (hwlayer->xfbc)<br>
> + addr += hwlayer->header_size_r;<br>
> +<br>
> + if (addr % 16)<br>
> + pr_err("layer addr[%d] is not 16 bytes align, it's 0x%08x\n",<br>
> + i, addr);<br>
> + layer->addr[i] = addr;<br>
> + }<br>
> +<br>
> + layer->pos = offset;<br>
> + layer->size = size;<br>
> + layer->crop_start = (hwlayer->src_y << 16) | hwlayer->src_x;<br>
> + layer->alpha = hwlayer->alpha;<br>
> +<br>
> + info = drm_format_info(hwlayer->format);<br>
> + if (info->cpp[0] == 0) {<br>
> + pr_err("layer[%d] bytes per pixel is invalid\n", hwlayer->index);<br>
> + return;<br>
> + }<br>
> +<br>
> + if (hwlayer->planes == 3)<br>
> + /* UV pitch is 1/2 of Y pitch*/<br>
> + layer->pitch = (hwlayer->pitch[0] / info->cpp[0]) |<br>
> + (hwlayer->pitch[0] / info->cpp[0] << 15);<br>
> + else<br>
> + layer->pitch = hwlayer->pitch[0] / info->cpp[0];<br>
> +<br>
> + layer->ctrl = dpu_img_ctrl(hwlayer->format, hwlayer->blending,<br>
> + hwlayer->xfbc, hwlayer->rotation);<br>
> +<br>
> + pr_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>
> + pr_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_scaling(struct dpu_context *ctx,<br>
> + struct sprd_dpu_layer layers[], u8 count)<br>
> +{<br>
> + int i;<br>
> + struct sprd_dpu_layer *top_layer;<br>
> +<br>
> + if (mode_changed) {<br>
> + top_layer = &layers[count - 1];<br>
> + pr_debug("------------------------------------\n");<br>
> + for (i = 0; i < count; i++) {<br>
> + pr_debug("layer[%d] : %dx%d --- (%d)\n", i,<br>
> + layers[i].dst_w, layers[i].dst_h,<br>
> + scale_copy.in_w);<br>
> + }<br>
> +<br>
> + if (top_layer->dst_w <= scale_copy.in_w) {<br>
> + dpu_sr_config(ctx);<br>
> + mode_changed = false;<br>
> +<br>
> + pr_info("do scaling enhace: 0x%x, top layer(%dx%d)\n",<br>
> + enhance_en, top_layer->dst_w,<br>
> + top_layer->dst_h);<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +static void dpu_flip(struct dpu_context *ctx,<br>
> + struct sprd_dpu_layer layers[], u8 count)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + int i;<br>
> + int y2r_coef;<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_DISPC_IF_EDPI)<br>
> + dpu_wait_stop_done(ctx);<br>
> +<br>
> + /* set Y2R conversion coef */<br>
> + y2r_coef = check_layer_y2r_coef(layers, count);<br>
> + if (y2r_coef >= 0) {<br>
> + /* write dpu_cfg0 register after dpu is in idle status */<br>
> + if (ctx->if_type == SPRD_DISPC_IF_DPI)<br>
> + dpu_stop(ctx);<br>
> +<br>
> + reg->dpu_cfg0 &= ~(0x7 << 4);<br>
> + reg->dpu_cfg0 |= (y2r_coef << 4);<br>
> + }<br>
> +<br>
> + /* reset the bgcolor to black */<br>
> + reg->bg_color = 0;<br>
> +<br>
> + /* disable all the layers */<br>
> + dpu_clean_all(ctx);<br>
> +<br>
> + /* to check if dpu need scaling the frame for SR */<br>
> + dpu_scaling(ctx, layers, count);<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_DISPC_IF_DPI) {<br>
> + if (!ctx->is_stopped) {<br>
> + reg->dpu_ctrl |= BIT(2);<br>
> + dpu_wait_update_done(ctx);<br>
> + } else if (y2r_coef >= 0) {<br>
> + reg->dpu_ctrl |= BIT(0);<br>
> + ctx->is_stopped = false;<br>
> + pr_info("dpu start\n");<br>
> + }<br>
> +<br>
> + reg->dpu_int_en |= DISPC_INT_ERR_MASK;<br>
> +<br>
> + } else if (ctx->if_type == SPRD_DISPC_IF_EDPI) {<br>
> + reg->dpu_ctrl |= BIT(0);<br>
> +<br>
> + ctx->is_stopped = false;<br>
> + }<br>
> +<br>
> + /*<br>
> + * If the following interrupt was disabled in isr,<br>
> + * re-enable it.<br>
> + */<br>
> + reg->dpu_int_en |= DISPC_INT_FBC_PLD_ERR_MASK |<br>
> + DISPC_INT_FBC_HDR_ERR_MASK |<br>
> + DISPC_INT_MMU_VAOR_RD_MASK |<br>
> + DISPC_INT_MMU_VAOR_WR_MASK |<br>
> + DISPC_INT_MMU_INV_RD_MASK |<br>
> + DISPC_INT_MMU_INV_WR_MASK;<br>
> +}<br>
> +<br>
> +static void dpu_dpi_init(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + u32 int_mask = 0;<br>
> +<br>
> + if (ctx->if_type == SPRD_DISPC_IF_DPI) {<br>
> + /* use dpi as interface */<br>
> + reg->dpu_cfg0 &= ~BIT(0);<br>
> +<br>
> + /* disable Halt function for SPRD DSI */<br>
> + reg->dpi_ctrl &= ~BIT(16);<br>
> +<br>
> + /* select te from external pad */<br>
> + reg->dpi_ctrl |= BIT(10);<br>
> +<br>
> + /* set dpi timing */<br>
> + reg->dpi_h_timing = (ctx->vm.hsync_len << 0) |<br>
> + (ctx->vm.hback_porch << 8) |<br>
> + (ctx->vm.hfront_porch << 20);<br>
> + reg->dpi_v_timing = (ctx->vm.vsync_len << 0) |<br>
> + (ctx->vm.vback_porch << 8) |<br>
> + (ctx->vm.vfront_porch << 20);<br>
> + if (ctx->vm.vsync_len + ctx->vm.vback_porch < 32)<br>
> + pr_warn("Warning: (vsync + vbp) < 32, "<br>
> + "underflow risk!\n");<br>
> +<br>
> + /* enable dpu update done INT */<br>
> + int_mask |= DISPC_INT_UPDATE_DONE_MASK;<br>
> + /* enable dpu DONE INT */<br>
> + int_mask |= DISPC_INT_DONE_MASK;<br>
> + /* enable dpu dpi vsync */<br>
> + int_mask |= DISPC_INT_DPI_VSYNC_MASK;<br>
> + /* enable dpu TE INT */<br>
> + int_mask |= DISPC_INT_TE_MASK;<br>
> + /* enable underflow err INT */<br>
> + int_mask |= DISPC_INT_ERR_MASK;<br>
> + /* enable write back done INT */<br>
> + int_mask |= DISPC_INT_WB_DONE_MASK;<br>
> + /* enable write back fail INT */<br>
> + int_mask |= DISPC_INT_WB_FAIL_MASK;<br>
> +<br>
> + } else if (ctx->if_type == SPRD_DISPC_IF_EDPI) {<br>
> + /* use edpi as interface */<br>
> + reg->dpu_cfg0 |= BIT(0);<br>
> +<br>
> + /* use external te */<br>
> + reg->dpi_ctrl |= BIT(10);<br>
> +<br>
> + /* enable te */<br>
> + reg->dpi_ctrl |= BIT(8);<br>
> +<br>
> + /* enable stop DONE INT */<br>
> + int_mask |= DISPC_INT_DONE_MASK;<br>
> + /* enable TE INT */<br>
> + int_mask |= DISPC_INT_TE_MASK;<br>
> + }<br>
> +<br>
> + /* enable ifbc payload error INT */<br>
> + int_mask |= DISPC_INT_FBC_PLD_ERR_MASK;<br>
> + /* enable ifbc header error INT */<br>
> + int_mask |= DISPC_INT_FBC_HDR_ERR_MASK;<br>
> + /* enable iommu va out of range read error INT */<br>
> + int_mask |= DISPC_INT_MMU_VAOR_RD_MASK;<br>
> + /* enable iommu va out of range write error INT */<br>
> + int_mask |= DISPC_INT_MMU_VAOR_WR_MASK;<br>
> + /* enable iommu invalid read error INT */<br>
> + int_mask |= DISPC_INT_MMU_INV_RD_MASK;<br>
> + /* enable iommu invalid write error INT */<br>
> + int_mask |= DISPC_INT_MMU_INV_WR_MASK;<br>
> +<br>
> + reg->dpu_int_en = int_mask;<br>
> +}<br>
> +<br>
> +static void enable_vsync(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + reg->dpu_int_en |= DISPC_INT_DPI_VSYNC_MASK;<br>
> +}<br>
> +<br>
> +static void disable_vsync(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + reg->dpu_int_en &= ~DISPC_INT_DPI_VSYNC_MASK;<br>
> +}<br>
> +<br>
> +static void dpu_enhance_backup(u32 id, void *param)<br>
> +{<br>
> + u32 *p;<br>
> +<br>
> + switch (id) {<br>
> + case ENHANCE_CFG_ID_ENABLE:<br>
> + p = param;<br>
> + enhance_en |= *p;<br>
> + pr_info("enhance enable backup: 0x%x\n", *p);<br>
> + break;<br>
> + case ENHANCE_CFG_ID_DISABLE:<br>
> + p = param;<br>
> + enhance_en &= ~(*p);<br>
> + if (*p & BIT(1))<br>
> + memset(&epf_copy, 0, sizeof(epf_copy));<br>
> + pr_info("enhance disable backup: 0x%x\n", *p);<br>
> + break;<br>
> + case ENHANCE_CFG_ID_SCL:<br>
> + memcpy(&scale_copy, param, sizeof(scale_copy));<br>
> + enhance_en |= BIT(0);<br>
> + pr_info("enhance scaling backup\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_HSV:<br>
> + memcpy(&hsv_copy, param, sizeof(hsv_copy));<br>
> + enhance_en |= BIT(2);<br>
> + pr_info("enhance hsv backup\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_CM:<br>
> + memcpy(&cm_copy, param, sizeof(cm_copy));<br>
> + enhance_en |= BIT(3);<br>
> + pr_info("enhance cm backup\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_SLP:<br>
> + memcpy(&slp_copy, param, sizeof(slp_copy));<br>
> + enhance_en |= BIT(4);<br>
> + pr_info("enhance slp backup\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_GAMMA:<br>
> + memcpy(&gamma_copy, param, sizeof(gamma_copy));<br>
> + enhance_en |= BIT(5);<br>
> + pr_info("enhance gamma backup\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_EPF:<br>
> + memcpy(&epf_copy, param, sizeof(epf_copy));<br>
> + if ((slp_copy.brightness > SLP_BRIGHTNESS_THRESHOLD) ||<br>
> + (enhance_en & BIT(0))) {<br>
> + enhance_en |= BIT(1);<br>
> + pr_info("enhance epf backup\n");<br>
> + }<br>
> + break;<br>
> + default:<br>
> + break;<br>
> + }<br>
> +}<br>
> +<br>
> +static void dpu_epf_set(struct dpu_reg *reg, struct epf_cfg *epf)<br>
> +{<br>
> + reg->epf_epsilon = (epf->epsilon1 << 16) | epf->epsilon0;<br>
> + reg->epf_gain0_3 = (epf->gain3 << 24) | (epf->gain2 << 16) |<br>
> + (epf->gain1 << 8) | epf->gain0;<br>
> + reg->epf_gain4_7 = (epf->gain7 << 24) | (epf->gain6 << 16) |<br>
> + (epf->gain5 << 8) | epf->gain4;<br>
> + reg->epf_diff = (epf->max_diff << 8) | epf->min_diff;<br>
> +}<br>
> +<br>
> +static void dpu_enhance_set(struct dpu_context *ctx, u32 id, void *param)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + struct scale_cfg *scale;<br>
> + struct cm_cfg *cm;<br>
> + struct slp_cfg *slp;<br>
> + struct gamma_lut *gamma;<br>
> + struct hsv_lut *hsv;<br>
> + struct epf_cfg *epf;<br>
> + u32 *p, i;<br>
> +<br>
> + if (!ctx->is_inited) {<br>
> + dpu_enhance_backup(id, param);<br>
> + return;<br>
> + }<br>
> +<br>
> + if (ctx->if_type == SPRD_DISPC_IF_EDPI)<br>
> + dpu_wait_stop_done(ctx);<br>
> +<br>
> + switch (id) {<br>
> + case ENHANCE_CFG_ID_ENABLE:<br>
> + p = param;<br>
> + reg->dpu_enhance_cfg |= *p;<br>
> + pr_info("enhance module enable: 0x%x\n", *p);<br>
> + break;<br>
> + case ENHANCE_CFG_ID_DISABLE:<br>
> + p = param;<br>
> + reg->dpu_enhance_cfg &= ~(*p);<br>
> + if (*p & BIT(1))<br>
> + memset(&epf_copy, 0, sizeof(epf_copy));<br>
> + pr_info("enhance module disable: 0x%x\n", *p);<br>
> + break;<br>
> + case ENHANCE_CFG_ID_SCL:<br>
> + memcpy(&scale_copy, param, sizeof(scale_copy));<br>
> + scale = &scale_copy;<br>
> + reg->blend_size = (scale->in_h << 16) | scale->in_w;<br>
> + reg->dpu_enhance_cfg |= BIT(0);<br>
> + pr_info("enhance scaling: %ux%u\n", scale->in_w, scale->in_h);<br>
> + break;<br>
> + case ENHANCE_CFG_ID_HSV:<br>
> + memcpy(&hsv_copy, param, sizeof(hsv_copy));<br>
> + hsv = &hsv_copy;<br>
> + for (i = 0; i < 360; i++) {<br>
> + reg->hsv_lut_addr = i;<br>
> + udelay(1);<br>
> + reg->hsv_lut_wdata = (hsv->table[i].sat << 16) |<br>
> + hsv->table[i].hue;<br>
> + }<br>
> + reg->dpu_enhance_cfg |= BIT(2);<br>
> + pr_info("enhance hsv set\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_CM:<br>
> + memcpy(&cm_copy, param, sizeof(cm_copy));<br>
> + cm = &cm_copy;<br>
> + reg->cm_coef01_00 = (cm->coef01 << 16) | cm->coef00;<br>
> + reg->cm_coef03_02 = (cm->coef03 << 16) | cm->coef02;<br>
> + reg->cm_coef11_10 = (cm->coef11 << 16) | cm->coef10;<br>
> + reg->cm_coef13_12 = (cm->coef13 << 16) | cm->coef12;<br>
> + reg->cm_coef21_20 = (cm->coef21 << 16) | cm->coef20;<br>
> + reg->cm_coef23_22 = (cm->coef23 << 16) | cm->coef22;<br>
> + reg->dpu_enhance_cfg |= BIT(3);<br>
> + pr_info("enhance cm set\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_SLP:<br>
> + memcpy(&slp_copy, param, sizeof(slp_copy));<br>
> + slp = &slp_copy;<br>
> + reg->slp_cfg0 = (slp->second_bright_factor << 24) |<br>
> + (slp->brightness_step << 16) |<br>
> + (slp->conversion_matrix << 8) |<br>
> + slp->brightness;<br>
> + reg->slp_cfg1 = (slp->first_max_bright_th << 8) |<br>
> + slp->first_percent_th;<br>
> + reg->dpu_enhance_cfg |= BIT(4);<br>
> + pr_info("enhance slp set\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_GAMMA:<br>
> + memcpy(&gamma_copy, param, sizeof(gamma_copy));<br>
> + gamma = &gamma_copy;<br>
> + for (i = 0; i < 256; i++) {<br>
> + reg->gamma_lut_addr = i;<br>
> + udelay(1);<br>
> + reg->gamma_lut_wdata = (gamma->r[i] << 20) |<br>
> + (gamma->g[i] << 10) |<br>
> + gamma->b[i];<br>
> + pr_debug("0x%02x: r=%u, g=%u, b=%u\n", i,<br>
> + gamma->r[i], gamma->g[i], gamma->b[i]);<br>
> + }<br>
> + reg->dpu_enhance_cfg |= BIT(5);<br>
> + pr_info("enhance gamma set\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_EPF:<br>
> + memcpy(&epf_copy, param, sizeof(epf_copy));<br>
> + if ((slp_copy.brightness > SLP_BRIGHTNESS_THRESHOLD) ||<br>
> + (enhance_en & BIT(0))) {<br>
> + epf = &epf_copy;<br>
> + dpu_epf_set(reg, epf);<br>
> + reg->dpu_enhance_cfg |= BIT(1);<br>
> + pr_info("enhance epf set\n");<br>
> + break;<br>
> + }<br>
> + return;<br>
> + default:<br>
> + break;<br>
> + }<br>
> +<br>
> + if ((ctx->if_type == SPRD_DISPC_IF_DPI) && !ctx->is_stopped) {<br>
> + reg->dpu_ctrl |= BIT(2);<br>
> + dpu_wait_update_done(ctx);<br>
> + } else if ((ctx->if_type == SPRD_DISPC_IF_EDPI) && panel_ready) {<br>
> + /*<br>
> + * In EDPI mode, we need to wait panel initializatin<br>
> + * completed. Otherwise, the dpu enhance settings may<br>
> + * start before panel initialization.<br>
> + */<br>
> + reg->dpu_ctrl |= BIT(0);<br>
> + ctx->is_stopped = false;<br>
> + }<br>
> +<br>
> + enhance_en = reg->dpu_enhance_cfg;<br>
> +}<br>
> +<br>
> +static void dpu_enhance_get(struct dpu_context *ctx, u32 id, void *param)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + struct scale_cfg *scale;<br>
> + struct epf_cfg *ep;<br>
> + struct slp_cfg *slp;<br>
> + struct gamma_lut *gamma;<br>
> + u32 *p32;<br>
> + int i, val;<br>
> +<br>
> + switch (id) {<br>
> + case ENHANCE_CFG_ID_ENABLE:<br>
> + p32 = param;<br>
> + *p32 = reg->dpu_enhance_cfg;<br>
> + pr_info("enhance module enable get\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_SCL:<br>
> + scale = param;<br>
> + val = reg->blend_size;<br>
> + scale->in_w = val & 0xffff;<br>
> + scale->in_h = val >> 16;<br>
> + pr_info("enhance scaling get\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_EPF:<br>
> + ep = param;<br>
> +<br>
> + val = reg->epf_epsilon;<br>
> + ep->epsilon0 = val;<br>
> + ep->epsilon1 = val >> 16;<br>
> +<br>
> + val = reg->epf_gain0_3;<br>
> + ep->gain0 = val;<br>
> + ep->gain1 = val >> 8;<br>
> + ep->gain2 = val >> 16;<br>
> + ep->gain3 = val >> 24;<br>
> +<br>
> + val = reg->epf_gain4_7;<br>
> + ep->gain4 = val;<br>
> + ep->gain5 = val >> 8;<br>
> + ep->gain6 = val >> 16;<br>
> + ep->gain7 = val >> 24;<br>
> +<br>
> + val = reg->epf_diff;<br>
> + ep->min_diff = val;<br>
> + ep->max_diff = val >> 8;<br>
> + pr_info("enhance epf get\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_HSV:<br>
> + dpu_stop(ctx);<br>
> + p32 = param;<br>
> + for (i = 0; i < 360; i++) {<br>
> + reg->hsv_lut_addr = i;<br>
> + udelay(1);<br>
> + *p32++ = reg->hsv_lut_rdata;<br>
> + }<br>
> + dpu_run(ctx);<br>
> + pr_info("enhance hsv get\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_CM:<br>
> + p32 = param;<br>
> + *p32++ = reg->cm_coef01_00;<br>
> + *p32++ = reg->cm_coef03_02;<br>
> + *p32++ = reg->cm_coef11_10;<br>
> + *p32++ = reg->cm_coef13_12;<br>
> + *p32++ = reg->cm_coef21_20;<br>
> + *p32++ = reg->cm_coef23_22;<br>
> + pr_info("enhance cm get\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_SLP:<br>
> + slp = param;<br>
> +<br>
> + val = reg->slp_cfg0;<br>
> + slp->brightness = val;<br>
> + slp->conversion_matrix = val >> 8;<br>
> + slp->brightness_step = val >> 16;<br>
> + slp->second_bright_factor = val >> 24;<br>
> +<br>
> + val = reg->slp_cfg1;<br>
> + slp->first_percent_th = val;<br>
> + slp->first_max_bright_th = val >> 8;<br>
> + pr_info("enhance slp get\n");<br>
> + break;<br>
> + case ENHANCE_CFG_ID_GAMMA:<br>
> + dpu_stop(ctx);<br>
> + gamma = param;<br>
> + for (i = 0; i < 256; i++) {<br>
> + reg->gamma_lut_addr = i;<br>
> + udelay(1);<br>
> + val = reg->gamma_lut_rdata;<br>
> + gamma->r[i] = (val >> 20) & 0x3FF;<br>
> + gamma->g[i] = (val >> 10) & 0x3FF;<br>
> + gamma->b[i] = val & 0x3FF;<br>
> + pr_debug("0x%02x: r=%u, g=%u, b=%u\n", i,<br>
> + gamma->r[i], gamma->g[i], gamma->b[i]);<br>
> + }<br>
> + dpu_run(ctx);<br>
> + pr_info("enhance gamma get\n");<br>
> + break;<br>
> + default:<br>
> + break;<br>
> + }<br>
> +}<br>
> +<br>
> +static void dpu_enhance_reload(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> + struct scale_cfg *scale;<br>
> + struct cm_cfg *cm;<br>
> + struct slp_cfg *slp;<br>
> + struct gamma_lut *gamma;<br>
> + struct hsv_lut *hsv;<br>
> + struct epf_cfg *epf;<br>
> + int i;<br>
> +<br>
> + if (enhance_en & BIT(0)) {<br>
> + scale = &scale_copy;<br>
> + reg->blend_size = (scale->in_h << 16) | scale->in_w;<br>
> + pr_info("enhance scaling from %ux%u to %ux%u\n", scale->in_w,<br>
> + scale->in_h, ctx->vm.hactive, ctx->vm.vactive);<br>
> + }<br>
> +<br>
> + if (enhance_en & BIT(1)) {<br>
> + epf = &epf_copy;<br>
> + dpu_epf_set(reg, epf);<br>
> + pr_info("enhance epf reload\n");<br>
> + }<br>
> +<br>
> + if (enhance_en & BIT(2)) {<br>
> + hsv = &hsv_copy;<br>
> + for (i = 0; i < 360; i++) {<br>
> + reg->hsv_lut_addr = i;<br>
> + udelay(1);<br>
> + reg->hsv_lut_wdata = (hsv->table[i].sat << 16) |<br>
> + hsv->table[i].hue;<br>
> + }<br>
> + pr_info("enhance hsv reload\n");<br>
> + }<br>
> +<br>
> + if (enhance_en & BIT(3)) {<br>
> + cm = &cm_copy;<br>
> + reg->cm_coef01_00 = (cm->coef01 << 16) | cm->coef00;<br>
> + reg->cm_coef03_02 = (cm->coef03 << 16) | cm->coef02;<br>
> + reg->cm_coef11_10 = (cm->coef11 << 16) | cm->coef10;<br>
> + reg->cm_coef13_12 = (cm->coef13 << 16) | cm->coef12;<br>
> + reg->cm_coef21_20 = (cm->coef21 << 16) | cm->coef20;<br>
> + reg->cm_coef23_22 = (cm->coef23 << 16) | cm->coef22;<br>
> + pr_info("enhance cm reload\n");<br>
> + }<br>
> +<br>
> + if (enhance_en & BIT(4)) {<br>
> + slp = &slp_copy;<br>
> + reg->slp_cfg0 = (slp->second_bright_factor << 24) |<br>
> + (slp->brightness_step << 16) |<br>
> + (slp->conversion_matrix << 8) |<br>
> + slp->brightness;<br>
> + reg->slp_cfg1 = (slp->first_max_bright_th << 8) |<br>
> + slp->first_percent_th;<br>
> + pr_info("enhance slp reload\n");<br>
> + }<br>
> +<br>
> + if (enhance_en & BIT(5)) {<br>
> + gamma = &gamma_copy;<br>
> + for (i = 0; i < 256; i++) {<br>
> + reg->gamma_lut_addr = i;<br>
> + udelay(1);<br>
> + reg->gamma_lut_wdata = (gamma->r[i] << 20) |<br>
> + (gamma->g[i] << 10) |<br>
> + gamma->b[i];<br>
> + pr_debug("0x%02x: r=%u, g=%u, b=%u\n", i,<br>
> + gamma->r[i], gamma->g[i], gamma->b[i]);<br>
> + }<br>
> + pr_info("enhance gamma reload\n");<br>
> + }<br>
> +<br>
> + reg->dpu_enhance_cfg = enhance_en;<br>
> +}<br>
> +<br>
> +static void dpu_sr_config(struct dpu_context *ctx)<br>
> +{<br>
> + struct dpu_reg *reg = (struct dpu_reg *)ctx->base;<br>
> +<br>
> + reg->blend_size = (scale_copy.in_h << 16) | scale_copy.in_w;<br>
> + if (need_scale) {<br>
> + /* SLP is disabled mode or bypass mode */<br>
> + if (slp_copy.brightness <= SLP_BRIGHTNESS_THRESHOLD) {<br>
> +<br>
> + /*<br>
> + * valid range of gain3 is [128,255];dpu_scaling maybe<br>
> + * called before epf_copy is assinged a value<br>
> + */<br>
> + if (epf_copy.gain3 > 0) {<br>
> + dpu_epf_set(reg, &epf_copy);<br>
> + enhance_en |= BIT(1);<br>
> + }<br>
> + }<br>
> + enhance_en |= BIT(0);<br>
> + reg->dpu_enhance_cfg = enhance_en;<br>
> + } else {<br>
> + if (slp_copy.brightness <= SLP_BRIGHTNESS_THRESHOLD)<br>
> + enhance_en &= ~(BIT(1));<br>
> +<br>
> + enhance_en &= ~(BIT(0));<br>
> + reg->dpu_enhance_cfg = enhance_en;<br>
> + }<br>
> +}<br>
> +<br>
> +static int dpu_modeset(struct dpu_context *ctx,<br>
> + struct drm_mode_modeinfo *mode)<br>
> +{<br>
> + scale_copy.in_w = mode->hdisplay;<br>
> + scale_copy.in_h = mode->vdisplay;<br>
> +<br>
> + if ((mode->hdisplay != ctx->vm.hactive) ||<br>
> + (mode->vdisplay != ctx->vm.vactive))<br>
> + need_scale = true;<br>
> + else<br>
> + need_scale = false;<br>
> +<br>
> + mode_changed = true;<br>
> + pr_info("begin switch to %u x %u\n", mode->hdisplay, mode->vdisplay);<br>
> +<br>
> + return 0;<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_BGRX8888,<br>
> + DRM_FORMAT_RGB565, DRM_FORMAT_BGR565,<br>
> + DRM_FORMAT_NV12, DRM_FORMAT_NV21,<br>
> + DRM_FORMAT_NV16, DRM_FORMAT_NV61,<br>
> + DRM_FORMAT_YUV420, DRM_FORMAT_YVU420,<br>
> +};<br>
> +<br>
> +static int dpu_capability(struct dpu_context *ctx,<br>
> + struct dpu_capability *cap)<br>
> +{<br>
> + if (!cap)<br>
> + return -EINVAL;<br>
> +<br>
> + cap->max_layers = 6;<br>
> + cap->fmts_ptr = primary_fmts;<br>
> + cap->fmts_cnt = ARRAY_SIZE(primary_fmts);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static struct dpu_core_ops dpu_r2p0_ops = {<br>
> + .parse_dt = dpu_parse_dt,<br>
> + .version = dpu_get_version,<br>
> + .init = dpu_init,<br>
> + .uninit = dpu_uninit,<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>
> + .bg_color = dpu_bgcolor,<br>
> + .enable_vsync = enable_vsync,<br>
> + .disable_vsync = disable_vsync,<br>
> + .enhance_set = dpu_enhance_set,<br>
> + .enhance_get = dpu_enhance_get,<br>
> + .modeset = dpu_modeset,<br>
> + .check_raw_int = dpu_check_raw_int,<br>
> +};<br>
> +<br>
> +static struct ops_entry entry = {<br>
> + .ver = "dpu-r2p0",<br>
> + .ops = &dpu_r2p0_ops,<br>
> +};<br>
> +<br>
> +static int __init dpu_core_register(void)<br>
> +{<br>
> + return dpu_core_ops_register(&entry);<br>
> +}<br>
> +<br>
> +subsys_initcall(dpu_core_register);<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..43142b3<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_dpu.c<br>
> @@ -0,0 +1,1152 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2019 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_irq.h><br>
> +#include <linux/pm_runtime.h><br>
> +<br>
> +#include <drm/drm_atomic_helper.h><br>
> +#include <drm/drm_crtc_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>
> +#include "sprd_gem.h"<br>
> +<br>
> +struct sprd_plane {<br>
> + struct drm_plane plane;<br>
> + struct drm_property *alpha_property;<br>
> + struct drm_property *blend_mode_property;<br>
> + struct drm_property *fbc_hsize_r_property;<br>
> + struct drm_property *fbc_hsize_y_property;<br>
> + struct drm_property *fbc_hsize_uv_property;<br>
> + struct drm_property *y2r_coef_property;<br>
> + struct drm_property *pallete_en_property;<br>
> + struct drm_property *pallete_color_property;<br>
> + u32 index;<br>
> +};<br>
> +<br>
> +struct sprd_plane_state {<br>
> + struct drm_plane_state state;<br>
> + u8 alpha;<br>
> + u8 blend_mode;<br>
> + u32 fbc_hsize_r;<br>
> + u32 fbc_hsize_y;<br>
> + u32 fbc_hsize_uv;<br>
> + u32 y2r_coef;<br>
> + u32 pallete_en;<br>
> + u32 pallete_color;<br>
> +};<br>
> +<br>
> +LIST_HEAD(dpu_core_head);<br>
> +LIST_HEAD(dpu_clk_head);<br>
> +LIST_HEAD(dpu_glb_head);<br>
> +<br>
> +static int sprd_dpu_init(struct sprd_dpu *dpu);<br>
> +static int sprd_dpu_uninit(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 inline struct<br>
> +sprd_plane_state *to_sprd_plane_state(const struct drm_plane_state *state)<br>
> +{<br>
> + return container_of(state, struct sprd_plane_state, state);<br>
> +}<br>
> +<br>
> +static int sprd_dpu_iommu_map(struct device *dev,<br>
> + struct sprd_gem_obj *sprd_gem)<br>
> +{<br>
> + /*<br>
> + * TODO:<br>
> + * Currently only supports dumb buffer,<br>
> + * will support iommu in the future.<br>
> + */<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_dpu_iommu_unmap(struct device *dev,<br>
> + struct sprd_gem_obj *sprd_gem)<br>
> +{<br>
> + /*<br>
> + * TODO:<br>
> + * Currently only supports dumb buffer,<br>
> + * will support iommu in the future.<br>
> + */<br>
> +}<br>
> +<br>
> +static int of_get_logo_memory_info(struct sprd_dpu *dpu,<br>
> + struct device_node *np)<br>
> +{<br>
> + struct device_node *node;<br>
> + struct resource r;<br>
> + int ret;<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + node = of_parse_phandle(np, "sprd,logo-memory", 0);<br>
> + if (!node) {<br>
> + DRM_INFO("no sprd,logo-memory specified\n");<br>
> + return 0;<br>
> + }<br>
> +<br>
> + ret = of_address_to_resource(node, 0, &r);<br>
> + of_node_put(node);<br>
> + if (ret) {<br>
> + DRM_ERROR("invalid logo reserved memory node!\n");<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + ctx->logo_addr = r.start;<br>
> + ctx->logo_size = resource_size(&r);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_plane_prepare_fb(struct drm_plane *plane,<br>
> + struct drm_plane_state *new_state)<br>
> +{<br>
> + struct drm_plane_state *curr_state = plane->state;<br>
> + struct drm_framebuffer *fb;<br>
> + struct drm_gem_object *obj;<br>
> + struct sprd_gem_obj *sprd_gem;<br>
> + struct sprd_dpu *dpu;<br>
> + int i;<br>
> +<br>
> + if ((curr_state->fb == new_state->fb) || !new_state->fb)<br>
> + return 0;<br>
> +<br>
> + fb = new_state->fb;<br>
> + dpu = crtc_to_dpu(new_state->crtc);<br>
> +<br>
> + if (!dpu->ctx.is_inited) {<br>
> + DRM_WARN("dpu has already powered off\n");<br>
> + return 0;<br>
> + }<br>
> +<br>
> + for (i = 0; i < fb->format->num_planes; i++) {<br>
> + obj = drm_gem_fb_get_obj(fb, i);<br>
> + sprd_gem = to_sprd_gem_obj(obj);<br>
> + if (sprd_gem->sgtb && sprd_gem->sgtb->nents > 1)<br>
> + sprd_dpu_iommu_map(&dpu->dev, sprd_gem);<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_plane_cleanup_fb(struct drm_plane *plane,<br>
> + struct drm_plane_state *old_state)<br>
> +{<br>
> + struct drm_plane_state *curr_state = plane->state;<br>
> + struct drm_framebuffer *fb;<br>
> + struct drm_gem_object *obj;<br>
> + struct sprd_gem_obj *sprd_gem;<br>
> + struct sprd_dpu *dpu;<br>
> + int i;<br>
> + static atomic_t logo2animation = { -1 };<br>
> +<br>
> + if ((curr_state->fb == old_state->fb) || !old_state->fb)<br>
> + return;<br>
> +<br>
> + fb = old_state->fb;<br>
> + dpu = crtc_to_dpu(old_state->crtc);<br>
> +<br>
> + if (!dpu->ctx.is_inited) {<br>
> + DRM_WARN("dpu has already powered off\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + for (i = 0; i < fb->format->num_planes; i++) {<br>
> + obj = drm_gem_fb_get_obj(fb, i);<br>
> + sprd_gem = to_sprd_gem_obj(obj);<br>
> + if (sprd_gem->sgtb && sprd_gem->sgtb->nents > 1)<br>
> + sprd_dpu_iommu_unmap(&dpu->dev, sprd_gem);<br>
> + }<br>
> +<br>
> + if (unlikely(atomic_inc_not_zero(&logo2animation)) &&<br>
> + dpu->ctx.logo_addr) {<br>
> + DRM_INFO("free logo memory addr:0x%lx size:0x%lx\n",<br>
> + dpu->ctx.logo_addr, dpu->ctx.logo_size);<br>
> + free_reserved_area(phys_to_virt(dpu->ctx.logo_addr),<br>
> + phys_to_virt(dpu->ctx.logo_addr + dpu->ctx.logo_size),<br>
> + -1, "logo");<br>
> + }<br>
> +}<br>
> +<br>
> +static int sprd_plane_atomic_check(struct drm_plane *plane,<br>
> + struct drm_plane_state *state)<br>
> +{<br>
> + DRM_DEBUG("%s()\n", __func__);<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 drm_gem_object *obj;<br>
> + struct sprd_gem_obj *sprd_gem;<br>
> + struct sprd_plane *p = to_sprd_plane(plane);<br>
> + struct sprd_plane_state *s = to_sprd_plane_state(state);<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(plane->state->crtc);<br>
> + struct sprd_dpu_layer *layer = &dpu->layers[p->index];<br>
> + int i;<br>
> +<br>
> + if (plane->state->crtc->state->active_changed) {<br>
> + DRM_DEBUG("resume or suspend, no need to update plane\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + if (s->pallete_en) {<br>
> + layer->index = p->index;<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 = s->alpha;<br>
> + layer->blending = s->blend_mode;<br>
> + layer->pallete_en = s->pallete_en;<br>
> + layer->pallete_color = s->pallete_color;<br>
> + dpu->pending_planes++;<br>
> + DRM_DEBUG("%s() pallete_color = %u, index = %u\n",<br>
> + __func__, layer->pallete_color, layer->index);<br>
> + return;<br>
> + }<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->rotation = state->rotation;<br>
> + layer->planes = fb->format->num_planes;<br>
> + layer->format = fb->format->format;<br>
> + layer->alpha = s->alpha;<br>
> + layer->blending = s->blend_mode;<br>
> + layer->xfbc = fb->modifier;<br>
> + layer->header_size_r = s->fbc_hsize_r;<br>
> + layer->header_size_y = s->fbc_hsize_y;<br>
> + layer->header_size_uv = s->fbc_hsize_uv;<br>
> + layer->y2r_coef = s->y2r_coef;<br>
> + layer->pallete_en = s->pallete_en;<br>
> + layer->pallete_color = s->pallete_color;<br>
> +<br>
> + DRM_DEBUG("%s() alpha = %u, blending = %u, rotation = %u, y2r_coef = %u\n",<br>
> + __func__, layer->alpha, layer->blending, layer->rotation, s->y2r_coef);<br>
> +<br>
> + DRM_DEBUG("%s() xfbc = %u, hsize_r = %u, hsize_y = %u, hsize_uv = %u\n",<br>
> + __func__, layer->xfbc, layer->header_size_r,<br>
> + layer->header_size_y, layer->header_size_uv);<br>
> +<br>
> + for (i = 0; i < layer->planes; i++) {<br>
> + obj = drm_gem_fb_get_obj(fb, i);<br>
> + sprd_gem = to_sprd_gem_obj(obj);<br>
> + layer->addr[i] = sprd_gem->dma_addr + fb->offsets[i];<br>
> + layer->pitch[i] = fb->pitches[i];<br>
> + }<br>
> +<br>
> + dpu->pending_planes++;<br>
> +}<br>
> +<br>
> +static void sprd_plane_atomic_disable(struct drm_plane *plane,<br>
> + struct drm_plane_state *old_state)<br>
> +{<br>
> + struct sprd_plane *p = to_sprd_plane(plane);<br>
> +<br>
> + /*<br>
> + * NOTE:<br>
> + * The dpu->core->flip() will disable all the planes each time.<br>
> + * So there is no need to impliment the atomic_disable() function.<br>
> + * But this function can not be removed, because it will change<br>
> + * to call atomic_update() callback instead. Which will cause<br>
> + * kernel panic in sprd_plane_atomic_update().<br>
> + *<br>
> + * We do nothing here but just print a debug log.<br>
> + */<br>
> + DRM_DEBUG("%s() layer_id = %u\n", __func__, p->index);<br>
> +}<br>
> +<br>
> +static void sprd_plane_reset(struct drm_plane *plane)<br>
> +{<br>
> + struct sprd_plane *p = to_sprd_plane(plane);<br>
> + struct sprd_plane_state *s;<br>
> +<br>
> + DRM_INFO("%s()\n", __func__);<br>
> +<br>
> + if (plane->state) {<br>
> + __drm_atomic_helper_plane_destroy_state(plane->state);<br>
> +<br>
> + s = to_sprd_plane_state(plane->state);<br>
> + memset(s, 0, sizeof(*s));<br>
> + } else {<br>
> + s = kzalloc(sizeof(*s), GFP_KERNEL);<br>
> + if (!s)<br>
> + return;<br>
> + plane->state = &s->state;<br>
> + }<br>
> +<br>
> + s->state.plane = plane;<br>
> + s->state.zpos = p->index;<br>
> + s->alpha = 255;<br>
> + s->blend_mode = DRM_MODE_BLEND_PIXEL_NONE;<br>
> +}<br>
> +<br>
> +static struct drm_plane_state *<br>
> +sprd_plane_atomic_duplicate_state(struct drm_plane *plane)<br>
> +{<br>
> + struct sprd_plane_state *s;<br>
> + struct sprd_plane_state *old_state = to_sprd_plane_state(plane->state);<br>
> +<br>
> + DRM_DEBUG("%s()\n", __func__);<br>
> +<br>
> + s = kzalloc(sizeof(*s), GFP_KERNEL);<br>
> + if (!s)<br>
> + return NULL;<br>
> +<br>
> + __drm_atomic_helper_plane_duplicate_state(plane, &s->state);<br>
> +<br>
> + WARN_ON(s->state.plane != plane);<br>
> +<br>
> + s->alpha = old_state->alpha;<br>
> + s->blend_mode = old_state->blend_mode;<br>
> + s->fbc_hsize_r = old_state->fbc_hsize_r;<br>
> + s->fbc_hsize_y = old_state->fbc_hsize_y;<br>
> + s->fbc_hsize_uv = old_state->fbc_hsize_uv;<br>
> + s->y2r_coef = old_state->y2r_coef;<br>
> + s->pallete_en = old_state->pallete_en;<br>
> + s->pallete_color = old_state->pallete_color;<br>
> +<br>
> + return &s->state;<br>
> +}<br>
> +<br>
> +static void sprd_plane_atomic_destroy_state(struct drm_plane *plane,<br>
> + struct drm_plane_state *state)<br>
> +{<br>
> + DRM_DEBUG("%s()\n", __func__);<br>
> +<br>
> + __drm_atomic_helper_plane_destroy_state(state);<br>
> + kfree(to_sprd_plane_state(state));<br>
> +}<br>
> +<br>
> +static int sprd_plane_atomic_set_property(struct drm_plane *plane,<br>
> + struct drm_plane_state *state,<br>
> + struct drm_property *property,<br>
> + u64 val)<br>
> +{<br>
> + struct sprd_plane *p = to_sprd_plane(plane);<br>
> + struct sprd_plane_state *s = to_sprd_plane_state(state);<br>
> +<br>
> + DRM_DEBUG("%s() name = %s, val = %llu\n",<br>
> + __func__, property->name, val);<br>
> +<br>
> + if (property == p->alpha_property)<br>
> + s->alpha = val;<br>
> + else if (property == p->blend_mode_property)<br>
> + s->blend_mode = val;<br>
> + else if (property == p->fbc_hsize_r_property)<br>
> + s->fbc_hsize_r = val;<br>
> + else if (property == p->fbc_hsize_y_property)<br>
> + s->fbc_hsize_y = val;<br>
> + else if (property == p->fbc_hsize_uv_property)<br>
> + s->fbc_hsize_uv = val;<br>
> + else if (property == p->y2r_coef_property)<br>
> + s->y2r_coef = val;<br>
> + else if (property == p->pallete_en_property)<br>
> + s->pallete_en = val;<br>
> + else if (property == p->pallete_color_property)<br>
> + s->pallete_color = val;<br>
> + else {<br>
> + DRM_ERROR("property %s is invalid\n", property->name);<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_plane_atomic_get_property(struct drm_plane *plane,<br>
> + const struct drm_plane_state *state,<br>
> + struct drm_property *property,<br>
> + u64 *val)<br>
> +{<br>
> + struct sprd_plane *p = to_sprd_plane(plane);<br>
> + const struct sprd_plane_state *s = to_sprd_plane_state(state);<br>
> +<br>
> + DRM_DEBUG("%s() name = %s\n", __func__, property->name);<br>
> +<br>
> + if (property == p->alpha_property)<br>
> + *val = s->alpha;<br>
> + else if (property == p->blend_mode_property)<br>
> + *val = s->blend_mode;<br>
> + else if (property == p->fbc_hsize_r_property)<br>
> + *val = s->fbc_hsize_r;<br>
> + else if (property == p->fbc_hsize_y_property)<br>
> + *val = s->fbc_hsize_y;<br>
> + else if (property == p->fbc_hsize_uv_property)<br>
> + *val = s->fbc_hsize_uv;<br>
> + else if (property == p->y2r_coef_property)<br>
> + *val = s->y2r_coef;<br>
> + else if (property == p->pallete_en_property)<br>
> + *val = s->pallete_en;<br>
> + else if (property == p->pallete_color_property)<br>
> + *val = s->pallete_color;<br>
> + else {<br>
> + DRM_ERROR("property %s is invalid\n", property->name);<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_plane_create_properties(struct sprd_plane *p, int index)<br>
> +{<br>
> + struct drm_property *prop;<br>
> + static const struct drm_prop_enum_list blend_mode_enum_list[] = {<br>
> + { DRM_MODE_BLEND_PIXEL_NONE, "None" },<br>
> + { DRM_MODE_BLEND_PREMULTI, "Pre-multiplied" },<br>
> + { DRM_MODE_BLEND_COVERAGE, "Coverage" },<br>
> + };<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 zpos property */<br>
> + drm_plane_create_zpos_immutable_property(&p->plane, index);<br>
> +<br>
> + /* create layer alpha property */<br>
> + prop = drm_property_create_range(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, 0, "alpha", 0, 255);<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop, 255);<br>
> + p->alpha_property = prop;<br>
> +<br>
> + /* create blend mode property */<br>
> + prop = drm_property_create_enum(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, DRM_MODE_PROP_ENUM,<br>
> + "pixel blend mode",<br>
> + blend_mode_enum_list,<br>
> + ARRAY_SIZE(blend_mode_enum_list));<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop,<br>
> + DRM_MODE_BLEND_PIXEL_NONE);<br>
> + p->blend_mode_property = prop;<br>
> +<br>
> + /* create fbc header size property */<br>
> + prop = drm_property_create_range(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, 0,<br>
> + "FBC header size RGB", 0, UINT_MAX);<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop, 0);<br>
> + p->fbc_hsize_r_property = prop;<br>
> +<br>
> + prop = drm_property_create_range(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, 0,<br>
> + "FBC header size Y", 0, UINT_MAX);<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop, 0);<br>
> + p->fbc_hsize_y_property = prop;<br>
> +<br>
> + prop = drm_property_create_range(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, 0,<br>
> + "FBC header size UV", 0, UINT_MAX);<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop, 0);<br>
> + p->fbc_hsize_uv_property = prop;<br>
> +<br>
> + /* create y2r coef property */<br>
> + prop = drm_property_create_range(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, 0,<br>
> + "YUV2RGB coef", 0, UINT_MAX);<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop, 0);<br>
> + p->y2r_coef_property = prop;<br>
> +<br>
> + /* create pallete enable property */<br>
> + prop = drm_property_create_range(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, 0,<br>
> + "pallete enable", 0, UINT_MAX);<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop, 0);<br>
> + p->pallete_en_property = prop;<br>
> +<br>
> + /* create pallete color property */<br>
> + prop = drm_property_create_range(p-><a href="http://plane.dev" rel="noreferrer" target="_blank">plane.dev</a>, 0,<br>
> + "pallete color", 0, UINT_MAX);<br>
> + if (!prop)<br>
> + return -ENOMEM;<br>
> + drm_object_attach_property(&p->plane.base, prop, 0);<br>
> + p->pallete_color_property = prop;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct drm_plane_helper_funcs sprd_plane_helper_funcs = {<br>
> + .prepare_fb = sprd_plane_prepare_fb,<br>
> + .cleanup_fb = sprd_plane_cleanup_fb,<br>
> + .atomic_check = sprd_plane_atomic_check,<br>
> + .atomic_update = sprd_plane_atomic_update,<br>
> + .atomic_disable = sprd_plane_atomic_disable,<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 = sprd_plane_reset,<br>
> + .atomic_duplicate_state = sprd_plane_atomic_duplicate_state,<br>
> + .atomic_destroy_state = sprd_plane_atomic_destroy_state,<br>
> + .atomic_set_property = sprd_plane_atomic_set_property,<br>
> + .atomic_get_property = sprd_plane_atomic_get_property,<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 err, i;<br>
> +<br>
> + if (dpu->core && dpu->core->capability)<br>
> + dpu->core->capability(&dpu->ctx, &cap);<br>
> +<br>
> + dpu->layers = devm_kcalloc(drm->dev, cap.max_layers,<br>
> + sizeof(struct sprd_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>
> + err = 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 (err) {<br>
> + DRM_ERROR("fail to init primary plane\n");<br>
> + return ERR_PTR(err);<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>
> + if (p)<br>
> + DRM_INFO("dpu plane init ok\n");<br>
> +<br>
> + return primary;<br>
> +}<br>
> +<br>
> +static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc)<br>
> +{<br>
> + struct sprd_dpu *dpu = crtc_to_dpu(crtc);<br>
> + struct drm_display_mode *mode = &crtc->state->adjusted_mode;<br>
> +<br>
> + DRM_INFO("%s() set mode: %s\n", __func__, dpu->mode->name);<br>
> +<br>
> + /*<br>
> + * TODO:<br>
> + * Currently, low simulator resolution only support<br>
> + * DPI mode, support for EDPI in the future.<br>
> + */<br>
> + if (mode->type & DRM_MODE_TYPE_BUILTIN) {<br>
> + dpu->ctx.if_type = SPRD_DISPC_IF_DPI;<br>
> + return;<br>
> + }<br>
> +<br>
> + if ((dpu->mode->hdisplay == dpu->mode->htotal) ||<br>
> + (dpu->mode->vdisplay == dpu->mode->vtotal))<br>
> + dpu->ctx.if_type = SPRD_DISPC_IF_EDPI;<br>
> + else<br>
> + dpu->ctx.if_type = SPRD_DISPC_IF_DPI;<br>
> +<br>
> + if (dpu->core && dpu->core->modeset) {<br>
> + if (crtc->state->mode_changed) {<br>
> + struct drm_mode_modeinfo umode;<br>
> +<br>
> + drm_mode_convert_to_umode(&umode, mode);<br>
> + dpu->core->modeset(&dpu->ctx, &umode);<br>
> + }<br>
> + }<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_INFO("%s() mode: "DRM_MODE_FMT"\n", __func__, DRM_MODE_ARG(mode));<br>
> +<br>
> + if (mode->type & DRM_MODE_TYPE_DEFAULT)<br>
> + dpu->mode = (struct drm_display_mode *)mode;<br>
> +<br>
> + if (mode->type & DRM_MODE_TYPE_PREFERRED) {<br>
> + dpu->mode = (struct drm_display_mode *)mode;<br>
> + drm_display_mode_to_videomode(dpu->mode, &dpu->ctx.vm);<br>
> + }<br>
> +<br>
> + if (mode->type & DRM_MODE_TYPE_BUILTIN)<br>
> + dpu->mode = (struct drm_display_mode *)mode;<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>
> + static bool is_enabled = true;<br>
> +<br>
> + DRM_INFO("%s()\n", __func__);<br>
> +<br>
> + /*<br>
> + * add if condition to avoid resume dpu for SR feature.<br>
> + */<br>
> + if (crtc->state->mode_changed && !crtc->state->active_changed)<br>
> + return;<br>
> +<br>
> + if (is_enabled)<br>
> + is_enabled = false;<br>
> + else<br>
> + pm_runtime_get_sync(dpu->dev.parent);<br>
> +<br>
> + sprd_dpu_init(dpu);<br>
> +<br>
> + enable_irq(dpu->ctx.irq);<br>
> +}<br>
> +<br>
> +static void sprd_crtc_wait_last_commit_complete(struct drm_crtc *crtc)<br>
> +{<br>
> + struct drm_crtc_commit *commit;<br>
> + int ret, i = 0;<br>
> +<br>
> + spin_lock(&crtc->commit_lock);<br>
> + list_for_each_entry(commit, &crtc->commit_list, commit_entry) {<br>
> + i++;<br>
> + /* skip the first entry, that's the current commit */<br>
> + if (i == 2)<br>
> + break;<br>
> + }<br>
> + if (i == 2)<br>
> + drm_crtc_commit_get(commit);<br>
> + spin_unlock(&crtc->commit_lock);<br>
> +<br>
> + if (i != 2)<br>
> + return;<br>
> +<br>
> + ret = wait_for_completion_interruptible_timeout(&commit->cleanup_done,<br>
> + HZ);<br>
> + if (ret == 0)<br>
> + DRM_WARN("wait last commit completion timed out\n");<br>
> +<br>
> + drm_crtc_commit_put(commit);<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>
> + DRM_INFO("%s()\n", __func__);<br>
> +<br>
> + /* add if condition to avoid suspend dpu for SR feature */<br>
> + if (crtc->state->mode_changed && !crtc->state->active_changed)<br>
> + return;<br>
> +<br>
> + sprd_crtc_wait_last_commit_complete(crtc);<br>
> +<br>
> + disable_irq(dpu->ctx.irq);<br>
> +<br>
> + sprd_dpu_uninit(dpu);<br>
> +<br>
> + pm_runtime_put(dpu->dev.parent);<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>
> + DRM_DEBUG("%s()\n", __func__);<br>
> +<br>
> + down(&dpu->ctx.refresh_lock);<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>
> + DRM_DEBUG("%s()\n", __func__);<br>
> +<br>
> + if (dpu->core && dpu->core->flip &&<br>
> + dpu->pending_planes && !dpu->ctx.disable_flip)<br>
> + dpu->core->flip(&dpu->ctx, dpu->layers, dpu->pending_planes);<br>
> +<br>
> + up(&dpu->ctx.refresh_lock);<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>
> + DRM_DEBUG("%s()\n", __func__);<br>
> +<br>
> + if (dpu->core && dpu->core->enable_vsync)<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>
> + DRM_DEBUG("%s()\n", __func__);<br>
> +<br>
> + if (dpu->core && dpu->core->disable_vsync)<br>
> + dpu->core->disable_vsync(&dpu->ctx);<br>
> +}<br>
> +<br>
> +static int sprd_crtc_create_properties(struct drm_crtc *crtc)<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>
> + struct drm_property *prop;<br>
> + struct drm_property_blob *blob;<br>
> + size_t blob_size;<br>
> +<br>
> + blob_size = strlen(dpu->ctx.version) + 1;<br>
> +<br>
> + blob = drm_property_create_blob(dpu-><a href="http://crtc.dev" rel="noreferrer" target="_blank">crtc.dev</a>, blob_size,<br>
> + dpu->ctx.version);<br>
> + if (IS_ERR(blob)) {<br>
> + DRM_ERROR("drm_property_create_blob dpu version failed\n");<br>
> + return PTR_ERR(blob);<br>
> + }<br>
> +<br>
> + /* create dpu version property */<br>
> + prop = drm_property_create(drm,<br>
> + DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB,<br>
> + "dpu version", 0);<br>
> + if (!prop) {<br>
> + DRM_ERROR("drm_property_create dpu version failed\n");<br>
> + return -ENOMEM;<br>
> + }<br>
> + drm_object_attach_property(&crtc->base, prop, blob-><a href="http://base.id" rel="noreferrer" target="_blank">base.id</a>);<br>
> +<br>
> + /* create corner size property */<br>
> + prop = drm_property_create(drm,<br>
> + DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_RANGE,<br>
> + "corner size", 0);<br>
> + if (!prop) {<br>
> + DRM_ERROR("drm_property_create corner size failed\n");<br>
> + return -ENOMEM;<br>
> + }<br>
> + drm_object_attach_property(&crtc->base, prop, dpu->ctx.corner_size);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct drm_crtc_helper_funcs sprd_crtc_helper_funcs = {<br>
> + .mode_set_nofb = sprd_crtc_mode_set_nofb,<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 err;<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>
> + err = drm_crtc_init_with_planes(drm, crtc, primary, NULL,<br>
> + &sprd_crtc_funcs, NULL);<br>
> + if (err) {<br>
> + DRM_ERROR("failed to init crtc.\n");<br>
> + return err;<br>
> + }<br>
> +<br>
> + drm_mode_crtc_set_gamma_size(crtc, 256);<br>
> +<br>
> + drm_crtc_helper_add(crtc, &sprd_crtc_helper_funcs);<br>
> +<br>
> + sprd_crtc_create_properties(crtc);<br>
> +<br>
> + DRM_INFO("%s() ok\n", __func__);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int sprd_dpu_run(struct sprd_dpu *dpu)<br>
> +{<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + down(&ctx->refresh_lock);<br>
> +<br>
> + if (!ctx->is_inited) {<br>
> + DRM_ERROR("dpu is not initialized\n");<br>
> + up(&ctx->refresh_lock);<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + if (!ctx->is_stopped) {<br>
> + up(&ctx->refresh_lock);<br>
> + return 0;<br>
> + }<br>
> +<br>
> + if (dpu->core && dpu->core->run)<br>
> + dpu->core->run(ctx);<br>
> +<br>
> + up(&ctx->refresh_lock);<br>
> +<br>
> + drm_crtc_vblank_on(&dpu->crtc);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int sprd_dpu_stop(struct sprd_dpu *dpu)<br>
> +{<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + down(&ctx->refresh_lock);<br>
> +<br>
> + if (!ctx->is_inited) {<br>
> + DRM_ERROR("dpu is not initialized\n");<br>
> + up(&ctx->refresh_lock);<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + if (ctx->is_stopped) {<br>
> + up(&ctx->refresh_lock);<br>
> + return 0;<br>
> + }<br>
> +<br>
> + if (dpu->core && dpu->core->stop)<br>
> + dpu->core->stop(ctx);<br>
> +<br>
> + up(&ctx->refresh_lock);<br>
> +<br>
> + drm_crtc_handle_vblank(&dpu->crtc);<br>
> + drm_crtc_vblank_off(&dpu->crtc);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_dpu_init(struct sprd_dpu *dpu)<br>
> +{<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + down(&ctx->refresh_lock);<br>
> +<br>
> + if (dpu->ctx.is_inited) {<br>
> + up(&ctx->refresh_lock);<br>
> + return 0;<br>
> + }<br>
> +<br>
> + if (dpu->glb && dpu->glb->power)<br>
> + dpu->glb->power(ctx, true);<br>
> + if (dpu->glb && dpu->glb->enable)<br>
> + dpu->glb->enable(ctx);<br>
> +<br>
> + if (ctx->is_stopped && dpu->glb && dpu->glb->reset)<br>
> + dpu->glb->reset(ctx);<br>
> +<br>
> + if (dpu->clk && dpu->clk->init)<br>
> + dpu->clk->init(ctx);<br>
> + if (dpu->clk && dpu->clk->enable)<br>
> + dpu->clk->enable(ctx);<br>
> +<br>
> + if (dpu->core && dpu->core->init)<br>
> + dpu->core->init(ctx);<br>
> + if (dpu->core && dpu->core->ifconfig)<br>
> + dpu->core->ifconfig(ctx);<br>
> +<br>
> + ctx->is_inited = true;<br>
> +<br>
> + up(&ctx->refresh_lock);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_dpu_uninit(struct sprd_dpu *dpu)<br>
> +{<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + down(&ctx->refresh_lock);<br>
> +<br>
> + if (!dpu->ctx.is_inited) {<br>
> + up(&ctx->refresh_lock);<br>
> + return 0;<br>
> + }<br>
> +<br>
> + if (dpu->core && dpu->core->uninit)<br>
> + dpu->core->uninit(ctx);<br>
> + if (dpu->clk && dpu->clk->disable)<br>
> + dpu->clk->disable(ctx);<br>
> + if (dpu->glb && dpu->glb->disable)<br>
> + dpu->glb->disable(ctx);<br>
> + if (dpu->glb && dpu->glb->power)<br>
> + dpu->glb->power(ctx, false);<br>
> +<br>
> + ctx->is_inited = false;<br>
> +<br>
> + up(&ctx->refresh_lock);<br>
> +<br>
> + return 0;<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>
> + if (dpu->core && dpu->core->isr)<br>
> + int_mask = dpu->core->isr(ctx);<br>
> +<br>
> + if (int_mask & DISPC_INT_TE_MASK) {<br>
> + if (ctx->te_check_en) {<br>
> + ctx->evt_te = true;<br>
> + wake_up_interruptible_all(&ctx->te_wq);<br>
> + }<br>
> + }<br>
> +<br>
> + if (int_mask & DISPC_INT_ERR_MASK)<br>
> + DRM_WARN("Warning: dpu underflow!\n");<br>
> +<br>
> + if ((int_mask & DISPC_INT_DPI_VSYNC_MASK) && ctx->is_inited)<br>
> + drm_crtc_handle_vblank(&dpu->crtc);<br>
> +<br>
> + return IRQ_HANDLED;<br>
> +}<br>
> +<br>
> +static int sprd_dpu_irq_request(struct sprd_dpu *dpu)<br>
> +{<br>
> + int err;<br>
> + int irq_num;<br>
> +<br>
> + irq_num = irq_of_parse_and_map(dpu->dev.of_node, 0);<br>
> + if (!irq_num) {<br>
> + DRM_ERROR("error: dpu parse irq num failed\n");<br>
> + return -EINVAL;<br>
> + }<br>
> + DRM_INFO("dpu irq_num = %d\n", irq_num);<br>
> +<br>
> + irq_set_status_flags(irq_num, IRQ_NOAUTOEN);<br>
> + err = devm_request_irq(&dpu->dev, irq_num, sprd_dpu_isr,<br>
> + 0, "DISPC", dpu);<br>
> + if (err) {<br>
> + DRM_ERROR("error: dpu request irq failed\n");<br>
> + return -EINVAL;<br>
> + }<br>
> + dpu->ctx.irq = irq_num;<br>
> + dpu->ctx.dpu_isr = sprd_dpu_isr;<br>
> +<br>
> + return 0;<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_drm *sprd = drm->dev_private;<br>
> + struct sprd_dpu *dpu = dev_get_drvdata(dev);<br>
> + struct drm_plane *plane;<br>
> + int err;<br>
> +<br>
> + DRM_INFO("%s()\n", __func__);<br>
> +<br>
> + plane = sprd_plane_init(drm, dpu);<br>
> + if (IS_ERR_OR_NULL(plane)) {<br>
> + err = PTR_ERR(plane);<br>
> + return err;<br>
> + }<br>
> +<br>
> + err = sprd_crtc_init(drm, &dpu->crtc, plane);<br>
> + if (err)<br>
> + return err;<br>
> +<br>
> + sprd_dpu_irq_request(dpu);<br>
> +<br>
> + sprd->dpu_dev = dev;<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_INFO("%s()\n", __func__);<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_node *np)<br>
> +{<br>
> + u32 temp;<br>
> + struct resource r;<br>
> + struct dpu_context *ctx = &dpu->ctx;<br>
> +<br>
> + if (dpu->core && dpu->core->parse_dt)<br>
> + dpu->core->parse_dt(&dpu->ctx, np);<br>
> + if (dpu->clk && dpu->clk->parse_dt)<br>
> + dpu->clk->parse_dt(&dpu->ctx, np);<br>
> + if (dpu->glb && dpu->glb->parse_dt)<br>
> + dpu->glb->parse_dt(&dpu->ctx, np);<br>
> +<br>
> + if (!of_property_read_u32(np, "sprd,dev-id", &temp))<br>
> + ctx->id = temp;<br>
> +<br>
> + if (of_address_to_resource(np, 0, &r)) {<br>
> + DRM_ERROR("parse dt base address failed\n");<br>
> + return -ENODEV;<br>
> + }<br>
> + ctx->base = (unsigned long)ioremap_nocache(r.start,<br>
> + resource_size(&r));<br>
> + if (ctx->base == 0) {<br>
> + DRM_ERROR("ioremap base address failed\n");<br>
> + return -EFAULT;<br>
> + }<br>
> +<br>
> + of_get_logo_memory_info(dpu, np);<br>
> +<br>
> + sema_init(&ctx->refresh_lock, 1);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_dpu_probe(struct platform_device *pdev)<br>
> +{<br>
> + struct device_node *np = pdev->dev.of_node;<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>
> + ret = sprd_dpu_context_init(dpu, np);<br>
> + if (ret)<br>
> + return ret;<br>
> +<br>
> + platform_set_drvdata(pdev, dpu);<br>
> + pm_runtime_set_active(&pdev->dev);<br>
> + pm_runtime_get_noresume(&pdev->dev);<br>
> + pm_runtime_enable(&pdev->dev);<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>
> +static const struct of_device_id dpu_match_table[] = {<br>
> + { .compatible = "sprd,display-processor",},<br>
> + {},<br>
> +};<br>
> +<br>
> +static 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>
> +module_platform_driver(sprd_dpu_driver);<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..998ebc7<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_dpu.h<br>
> @@ -0,0 +1,217 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2019 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>
> +#include "disp_lib.h"<br>
> +<br>
> +#define DISPC_INT_DONE_MASK BIT(0)<br>
> +#define DISPC_INT_TE_MASK BIT(1)<br>
> +#define DISPC_INT_ERR_MASK BIT(2)<br>
> +#define DISPC_INT_EDPI_TE_MASK BIT(3)<br>
> +#define DISPC_INT_UPDATE_DONE_MASK BIT(4)<br>
> +#define DISPC_INT_DPI_VSYNC_MASK BIT(5)<br>
> +#define DISPC_INT_WB_DONE_MASK BIT(6)<br>
> +#define DISPC_INT_WB_FAIL_MASK BIT(7)<br>
> +<br>
> +/* NOTE: this mask is not a realy dpu interrupt mask */<br>
> +#define DISPC_INT_FENCE_SIGNAL_REQUEST BIT(31)<br>
> +<br>
> +enum {<br>
> + SPRD_DISPC_IF_DBI = 0,<br>
> + SPRD_DISPC_IF_DPI,<br>
> + SPRD_DISPC_IF_EDPI,<br>
> + SPRD_DISPC_IF_LIMIT<br>
> +};<br>
> +<br>
> +enum {<br>
> + SPRD_IMG_DATA_ENDIAN_B0B1B2B3 = 0,<br>
> + SPRD_IMG_DATA_ENDIAN_B3B2B1B0,<br>
> + SPRD_IMG_DATA_ENDIAN_B2B3B0B1,<br>
> + SPRD_IMG_DATA_ENDIAN_B1B0B3B2,<br>
> + SPRD_IMG_DATA_ENDIAN_LIMIT<br>
> +};<br>
> +<br>
> +enum {<br>
> + DISPC_CLK_ID_CORE = 0,<br>
> + DISPC_CLK_ID_DBI,<br>
> + DISPC_CLK_ID_DPI,<br>
> + DISPC_CLK_ID_MAX<br>
> +};<br>
> +<br>
> +enum {<br>
> + ENHANCE_CFG_ID_ENABLE,<br>
> + ENHANCE_CFG_ID_DISABLE,<br>
> + ENHANCE_CFG_ID_SCL,<br>
> + ENHANCE_CFG_ID_EPF,<br>
> + ENHANCE_CFG_ID_HSV,<br>
> + ENHANCE_CFG_ID_CM,<br>
> + ENHANCE_CFG_ID_SLP,<br>
> + ENHANCE_CFG_ID_GAMMA,<br>
> + ENHANCE_CFG_ID_LTM,<br>
> + ENHANCE_CFG_ID_CABC,<br>
> + ENHANCE_CFG_ID_SLP_LUT,<br>
> + ENHANCE_CFG_ID_LUT3D,<br>
> + ENHANCE_CFG_ID_MAX<br>
> +};<br>
> +<br>
> +struct sprd_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>
> + u32 xfbc;<br>
> + u32 height;<br>
> + u32 header_size_r;<br>
> + u32 header_size_y;<br>
> + u32 header_size_uv;<br>
> + u32 y2r_coef;<br>
> + u8 pallete_en;<br>
> + u32 pallete_color;<br>
> +};<br>
> +<br>
> +struct dpu_capability {<br>
> + u32 max_layers;<br>
> + const u32 *fmts_ptr;<br>
> + u32 fmts_cnt;<br>
> +};<br>
> +<br>
> +struct dpu_context;<br>
> +<br>
> +struct dpu_core_ops {<br>
> + int (*parse_dt)(struct dpu_context *ctx,<br>
> + struct device_node *np);<br>
> + u32 (*version)(struct dpu_context *ctx);<br>
> + int (*init)(struct dpu_context *ctx);<br>
> + void (*uninit)(struct dpu_context *ctx);<br>
> + void (*run)(struct dpu_context *ctx);<br>
> + void (*stop)(struct dpu_context *ctx);<br>
> + void (*disable_vsync)(struct dpu_context *ctx);<br>
> + void (*enable_vsync)(struct dpu_context *ctx);<br>
> + u32 (*isr)(struct dpu_context *ctx);<br>
> + void (*ifconfig)(struct dpu_context *ctx);<br>
> + void (*write_back)(struct dpu_context *ctx, u8 count, bool debug);<br>
> + void (*flip)(struct dpu_context *ctx,<br>
> + struct sprd_dpu_layer layers[], u8 count);<br>
> + int (*capability)(struct dpu_context *ctx,<br>
> + struct dpu_capability *cap);<br>
> + void (*bg_color)(struct dpu_context *ctx, u32 color);<br>
> + void (*enhance_set)(struct dpu_context *ctx, u32 id, void *param);<br>
> + void (*enhance_get)(struct dpu_context *ctx, u32 id, void *param);<br>
> + int (*modeset)(struct dpu_context *ctx,<br>
> + struct drm_mode_modeinfo *mode);<br>
> + bool (*check_raw_int)(struct dpu_context *ctx, u32 mask);<br>
> +};<br>
> +<br>
> +struct dpu_clk_ops {<br>
> + int (*parse_dt)(struct dpu_context *ctx,<br>
> + struct device_node *np);<br>
> + int (*init)(struct dpu_context *ctx);<br>
> + int (*uinit)(struct dpu_context *ctx);<br>
> + int (*enable)(struct dpu_context *ctx);<br>
> + int (*disable)(struct dpu_context *ctx);<br>
> + int (*update)(struct dpu_context *ctx, int clk_id, int val);<br>
> +};<br>
> +<br>
> +struct dpu_glb_ops {<br>
> + int (*parse_dt)(struct dpu_context *ctx,<br>
> + struct device_node *np);<br>
> + void (*enable)(struct dpu_context *ctx);<br>
> + void (*disable)(struct dpu_context *ctx);<br>
> + void (*reset)(struct dpu_context *ctx);<br>
> + void (*power)(struct dpu_context *ctx, int enable);<br>
> +};<br>
> +<br>
> +struct dpu_context {<br>
> + unsigned long base;<br>
> + u32 base_offset[2];<br>
> + const char *version;<br>
> + u32 corner_size;<br>
> + int irq;<br>
> + u8 if_type;<br>
> + u8 id;<br>
> + bool is_inited;<br>
> + bool is_stopped;<br>
> + bool disable_flip;<br>
> + struct videomode vm;<br>
> + struct semaphore refresh_lock;<br>
> + struct work_struct wb_work;<br>
> + struct tasklet_struct dvfs_task;<br>
> + u32 wb_addr_p;<br>
> + irqreturn_t (*dpu_isr)(int irq, void *data);<br>
> + wait_queue_head_t te_wq;<br>
> + bool te_check_en;<br>
> + bool evt_te;<br>
> + unsigned long logo_addr;<br>
> + unsigned long logo_size;<br>
> + struct work_struct cabc_work;<br>
> + struct work_struct cabc_bl_update;<br>
> +};<br>
> +<br>
> +struct sprd_dpu {<br>
> + struct device dev;<br>
> + struct drm_crtc crtc;<br>
> + struct dpu_context ctx;<br>
> + struct dpu_core_ops *core;<br>
> + struct dpu_clk_ops *clk;<br>
> + struct dpu_glb_ops *glb;<br>
> + struct drm_display_mode *mode;<br>
> + struct sprd_dpu_layer *layers;<br>
> + u8 pending_planes;<br>
> +};<br>
> +<br>
> +extern struct list_head dpu_core_head;<br>
> +extern struct list_head dpu_clk_head;<br>
> +extern struct list_head dpu_glb_head;<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>
> +#define dpu_core_ops_register(entry) \<br>
> + disp_ops_register(entry, &dpu_core_head)<br>
> +#define dpu_clk_ops_register(entry) \<br>
> + disp_ops_register(entry, &dpu_clk_head)<br>
> +#define dpu_glb_ops_register(entry) \<br>
> + disp_ops_register(entry, &dpu_glb_head)<br>
> +<br>
> +#define dpu_core_ops_attach(str) \<br>
> + disp_ops_attach(str, &dpu_core_head)<br>
> +#define dpu_clk_ops_attach(str) \<br>
> + disp_ops_attach(str, &dpu_clk_head)<br>
> +#define dpu_glb_ops_attach(str) \<br>
> + disp_ops_attach(str, &dpu_glb_head)<br>
> +<br>
> +int sprd_dpu_run(struct sprd_dpu *dpu);<br>
> +int sprd_dpu_stop(struct sprd_dpu *dpu);<br>
> +<br>
> +#endif<br>
> <br>
<br>
-- <br>
Thomas Zimmermann<br>
Graphics Driver Developer<br>
SUSE Software Solutions Germany GmbH<br>
Maxfeldstr. 5, 90409 Nürnberg, Germany<br>
(HRB 36809, AG Nürnberg)<br>
Geschäftsführer: Felix Imendörffer<br>
<br>
</blockquote></div></div>