<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Daniel Vetter <<a href="mailto:daniel@ffwll.ch">daniel@ffwll.ch</a>> 于2021年2月3日周三 下午10:37写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Jan 05, 2021 at 09:46:07PM +0800, Kevin Tang wrote:<br>
> Adds dsi host controller support for the Unisoc's display subsystem.<br>
> Adds dsi phy support for the Unisoc's display subsystem.<br>
> Only MIPI DSI Displays supported, DP/TV/HMDI will be support<br>
> in the feature.<br>
> <br>
> v1:<br>
> - Remove dphy and dsi graph binding, merge the dphy driver into the dsi.<br>
> <br>
> v2:<br>
> - Use drm_xxx to replace all DRM_XXX.<br>
> - Use kzalloc to replace devm_kzalloc for sprd_dsi structure init.<br>
<br>
Similar comments about kzalloc as with the previous sprd patch. Otherwise<br>
just two questions:<br>
<br>
dw-dsi is named at least like the synopsys driver we have already,<br>
wouldn't this fit into the drm/bridge driver we have? Ack from bridge<br>
people (just cc everyone for that dw_dsi driver to get their attention)<br>
would be good.<br></blockquote><div>dw dsi controller is not a standard synopsys ip, we have updated a lot on the basic ip version, the entire control register is different. <br></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>i think this is a good suggestion</span></span></span> , i will cc to drm/bridge reviewers and maintainers, thank you.<br></span></span></span> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Other thing is the header definitions for the registers. bitfields and<br>
unions are rather unusual for this, and to my understanding might blow up<br>
on different compilers. Results in rather verbose and unusual code, but<br>
since you only read/write full bytes at least it should be all save. Imo<br>
not a worry.<br></blockquote><div> <span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>We have been using this way for many years and it seems that we haven’t found any problems,</span></span></span></div><div><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span><span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span>it does seem that there will be some unused bitfields,<span class="gmail-VIiyi" lang="en"><span class="gmail-JLqJ4b gmail-ChMk0b"><span> i don’t know if this will be a problem...</span></span></span> </span></span></span> </span></span></span> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
See below for the kzalloc comments.<br></blockquote><div>Got it. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-Daniel<br>
<br>
> ---<br>
> drivers/gpu/drm/sprd/Makefile | 7 +-<br>
> drivers/gpu/drm/sprd/dw_dsi_ctrl.c | 794 +++++++++++++++++<br>
> drivers/gpu/drm/sprd/dw_dsi_ctrl.h | 1475 ++++++++++++++++++++++++++++++++<br>
> drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.c | 157 ++++<br>
> drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.h | 26 +<br>
> drivers/gpu/drm/sprd/megacores_pll.c | 317 +++++++<br>
> drivers/gpu/drm/sprd/megacores_pll.h | 146 ++++<br>
> drivers/gpu/drm/sprd/sprd_drm.c | 1 +<br>
> drivers/gpu/drm/sprd/sprd_drm.h | 1 +<br>
> drivers/gpu/drm/sprd/sprd_dsi.c | 1162 +++++++++++++++++++++++++<br>
> drivers/gpu/drm/sprd/sprd_dsi.h | 107 +++<br>
> 11 files changed, 4191 insertions(+), 2 deletions(-)<br>
> create mode 100644 drivers/gpu/drm/sprd/dw_dsi_ctrl.c<br>
> create mode 100644 drivers/gpu/drm/sprd/dw_dsi_ctrl.h<br>
> create mode 100644 drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.c<br>
> create mode 100644 drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.h<br>
> create mode 100644 drivers/gpu/drm/sprd/megacores_pll.c<br>
> create mode 100644 drivers/gpu/drm/sprd/megacores_pll.h<br>
> create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.c<br>
> create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.h<br>
> <br>
> diff --git a/drivers/gpu/drm/sprd/Makefile b/drivers/gpu/drm/sprd/Makefile<br>
> index 6c25bfa..d49f497 100644<br>
> --- a/drivers/gpu/drm/sprd/Makefile<br>
> +++ b/drivers/gpu/drm/sprd/Makefile<br>
> @@ -1,5 +1,8 @@<br>
> # SPDX-License-Identifier: GPL-2.0<br>
> <br>
> obj-y := sprd_drm.o \<br>
> - sprd_dpu.o<br>
> -<br>
> + sprd_dpu.o \<br>
> + sprd_dsi.o \<br>
> + dw_dsi_ctrl.o \<br>
> + dw_dsi_ctrl_ppi.o \<br>
> + megacores_pll.o<br>
> diff --git a/drivers/gpu/drm/sprd/dw_dsi_ctrl.c b/drivers/gpu/drm/sprd/dw_dsi_ctrl.c<br>
> new file mode 100644<br>
> index 0000000..1034aba<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dw_dsi_ctrl.c<br>
> @@ -0,0 +1,794 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <linux/io.h><br>
> +#include <linux/init.h><br>
> +#include <linux/delay.h><br>
> +#include <linux/module.h><br>
> +<br>
> +#include "dw_dsi_ctrl.h"<br>
> +<br>
> +/*<br>
> + * Modify power status of DSI Host core<br>
> + */<br>
> +void dsi_power_enable(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(enable, ®->SOFT_RESET);<br>
> +}<br>
> +/*<br>
> + * Enable/disable DPI video mode<br>
> + */<br>
> +void dsi_video_mode(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(0, ®->DSI_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Enable command mode (Generic interface)<br>
> + */<br>
> +void dsi_cmd_mode(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(1, ®->DSI_MODE_CFG);<br>
> +}<br>
> +<br>
> +bool dsi_is_cmd_mode(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + return readl(®->DSI_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Configure the read back virtual channel for the generic interface<br>
> + */<br>
> +void dsi_rx_vcid(struct dsi_context *ctx, u8 vc)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x1C virtual_channel_id;<br>
> +<br>
> + virtual_channel_id.val = readl(®->VIRTUAL_CHANNEL_ID);<br>
> + virtual_channel_id.bits.gen_rx_vcid = vc;<br>
> +<br>
> + writel(virtual_channel_id.val, ®->VIRTUAL_CHANNEL_ID);<br>
> +}<br>
> +/*<br>
> + * Write the DPI video virtual channel destination<br>
> + */<br>
> +void dsi_video_vcid(struct dsi_context *ctx, u8 vc)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x1C virtual_channel_id;<br>
> +<br>
> + virtual_channel_id.val = readl(®->VIRTUAL_CHANNEL_ID);<br>
> + virtual_channel_id.bits.video_pkt_vcid = vc;<br>
> +<br>
> + writel(virtual_channel_id.val, ®->VIRTUAL_CHANNEL_ID);<br>
> +}<br>
> +/*<br>
> + * Set DPI video mode type (burst/non-burst - with sync pulses or events)<br>
> + */<br>
> +void dsi_dpi_video_burst_mode(struct dsi_context *ctx, int mode)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x38 vid_mode_cfg;<br>
> +<br>
> + vid_mode_cfg.val = readl(®->VID_MODE_CFG);<br>
> + vid_mode_cfg.bits.vid_mode_type = mode;<br>
> +<br>
> + writel(vid_mode_cfg.val, ®->VID_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Set DPI video color coding<br>
> + */<br>
> +void dsi_dpi_color_coding(struct dsi_context *ctx, int coding)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x20 dpi_video_format;<br>
> +<br>
> + dpi_video_format.val = readl(®->DPI_VIDEO_FORMAT);<br>
> + dpi_video_format.bits.dpi_video_mode_format = coding;<br>
> +<br>
> + writel(dpi_video_format.val, ®->DPI_VIDEO_FORMAT);<br>
> +}<br>
> +/*<br>
> + * Configure the Horizontal Line time<br>
> + * param "byte_cycle" taken to transmit the total of the horizontal line<br>
> + */<br>
> +void dsi_dpi_hline_time(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x2C video_line_time;<br>
> +<br>
> + video_line_time.val = readl(®->VIDEO_LINE_TIME);<br>
> + video_line_time.bits.video_line_time = byte_cycle;<br>
> +<br>
> + writel(video_line_time.val, ®->VIDEO_LINE_TIME);<br>
> +}<br>
> +/*<br>
> + * Configure the Horizontal back porch time<br>
> + * param "byte_cycle" taken to transmit the horizontal back porch<br>
> + */<br>
> +void dsi_dpi_hbp_time(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x28 video_line_hblk_time;<br>
> +<br>
> + video_line_hblk_time.val = readl(®->VIDEO_LINE_HBLK_TIME);<br>
> + video_line_hblk_time.bits.video_line_hbp_time = byte_cycle;<br>
> +<br>
> + writel(video_line_hblk_time.val, ®->VIDEO_LINE_HBLK_TIME);<br>
> +}<br>
> +/*<br>
> + * Configure the Horizontal sync time,<br>
> + * param "byte_cycle" taken to transmit the horizontal sync<br>
> + */<br>
> +void dsi_dpi_hsync_time(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x28 video_line_hblk_time;<br>
> +<br>
> + video_line_hblk_time.val = readl(®->VIDEO_LINE_HBLK_TIME);<br>
> + video_line_hblk_time.bits.video_line_hsa_time = byte_cycle;<br>
> +<br>
> + writel(video_line_hblk_time.val, ®->VIDEO_LINE_HBLK_TIME);<br>
> +}<br>
> +/*<br>
> + * Configure the vertical active lines of the video stream<br>
> + */<br>
> +void dsi_dpi_vact(struct dsi_context *ctx, u16 lines)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x34 video_active_lines;<br>
> +<br>
> + video_active_lines.val = readl(®->VIDEO_VACTIVE_LINES);<br>
> + video_active_lines.bits.vactive_lines = lines;<br>
> +<br>
> + writel(video_active_lines.val, ®->VIDEO_VACTIVE_LINES);<br>
> +}<br>
> +<br>
> +void dsi_dpi_vfp(struct dsi_context *ctx, u16 lines)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x30 video_vblk_lines;<br>
> +<br>
> + video_vblk_lines.val = readl(®->VIDEO_VBLK_LINES);<br>
> + video_vblk_lines.bits.vfp_lines = lines;<br>
> +<br>
> + writel(video_vblk_lines.val, ®->VIDEO_VBLK_LINES);<br>
> +}<br>
> +<br>
> +void dsi_dpi_vbp(struct dsi_context *ctx, u16 lines)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x30 video_vblk_lines;<br>
> +<br>
> + video_vblk_lines.val = readl(®->VIDEO_VBLK_LINES);<br>
> + video_vblk_lines.bits.vbp_lines = lines;<br>
> +<br>
> + writel(video_vblk_lines.val, ®->VIDEO_VBLK_LINES);<br>
> +}<br>
> +<br>
> +void dsi_dpi_vsync(struct dsi_context *ctx, u16 lines)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x30 video_vblk_lines;<br>
> +<br>
> + video_vblk_lines.val = readl(®->VIDEO_VBLK_LINES);<br>
> + video_vblk_lines.bits.vsa_lines = lines;<br>
> +<br>
> + writel(video_vblk_lines.val, ®->VIDEO_VBLK_LINES);<br>
> +}<br>
> +<br>
> +void dsi_dpi_hporch_lp_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x38 vid_mode_cfg;<br>
> +<br>
> + vid_mode_cfg.val = readl(®->VID_MODE_CFG);<br>
> +<br>
> + vid_mode_cfg.bits.lp_hfp_en = enable;<br>
> + vid_mode_cfg.bits.lp_hbp_en = enable;<br>
> +<br>
> + writel(vid_mode_cfg.val, ®->VID_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Enable return to low power mode inside vertical active lines periods when<br>
> + * timing allows<br>
> + */<br>
> +void dsi_dpi_vporch_lp_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x38 vid_mode_cfg;<br>
> +<br>
> + vid_mode_cfg.val = readl(®->VID_MODE_CFG);<br>
> +<br>
> + vid_mode_cfg.bits.lp_vact_en = enable;<br>
> + vid_mode_cfg.bits.lp_vfp_en = enable;<br>
> + vid_mode_cfg.bits.lp_vbp_en = enable;<br>
> + vid_mode_cfg.bits.lp_vsa_en = enable;<br>
> +<br>
> + writel(vid_mode_cfg.val, ®->VID_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Enable FRAME BTA ACK<br>
> + */<br>
> +void dsi_dpi_frame_ack_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x38 vid_mode_cfg;<br>
> +<br>
> + vid_mode_cfg.val = readl(®->VID_MODE_CFG);<br>
> + vid_mode_cfg.bits.frame_bta_ack_en = enable;<br>
> +<br>
> + writel(vid_mode_cfg.val, ®->VID_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Write no of chunks to core - taken into consideration only when multi packet<br>
> + * is enabled<br>
> + */<br>
> +void dsi_dpi_chunk_num(struct dsi_context *ctx, u16 num)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x24 video_pkt_config;<br>
> +<br>
> + video_pkt_config.val = readl(®->VIDEO_PKT_CONFIG);<br>
> + video_pkt_config.bits.video_line_chunk_num = num;<br>
> +<br>
> + writel(video_pkt_config.val, ®->VIDEO_PKT_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Write the null packet size - will only be taken into account when null<br>
> + * packets are enabled.<br>
> + */<br>
> +void dsi_dpi_null_packet_size(struct dsi_context *ctx, u16 size)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xC0 video_nullpkt_size;<br>
> +<br>
> + video_nullpkt_size.val = readl(®->VIDEO_NULLPKT_SIZE);<br>
> + video_nullpkt_size.bits.video_nullpkt_size = size;<br>
> +<br>
> + writel(video_nullpkt_size.val, ®->VIDEO_NULLPKT_SIZE);<br>
> +}<br>
> +/*<br>
> + * Write video packet size. obligatory for sending video<br>
> + */<br>
> +void dsi_dpi_video_packet_size(struct dsi_context *ctx, u16 size)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x24 video_pkt_config;<br>
> +<br>
> + video_pkt_config.val = readl(®->VIDEO_PKT_CONFIG);<br>
> + video_pkt_config.bits.video_pkt_size = size;<br>
> +<br>
> + writel(video_pkt_config.val, ®->VIDEO_PKT_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Specifiy the size of the packet memory write start/continue<br>
> + */<br>
> +void dsi_edpi_max_pkt_size(struct dsi_context *ctx, u16 size)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xC4 dcs_wm_pkt_size;<br>
> +<br>
> + dcs_wm_pkt_size.val = readl(®->DCS_WM_PKT_SIZE);<br>
> + dcs_wm_pkt_size.bits.dcs_wm_pkt_size = size;<br>
> +<br>
> + writel(dcs_wm_pkt_size.val, ®->DCS_WM_PKT_SIZE);<br>
> +}<br>
> +/*<br>
> + * Enable tear effect acknowledge<br>
> + */<br>
> +void dsi_tear_effect_ack_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x68 cmd_mode_cfg;<br>
> +<br>
> + cmd_mode_cfg.val = readl(®->CMD_MODE_CFG);<br>
> + cmd_mode_cfg.bits.tear_fx_en = enable;<br>
> +<br>
> + writel(cmd_mode_cfg.val, ®->CMD_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Set DCS command packet transmission to transmission type<br>
> + */<br>
> +void dsi_cmd_mode_lp_cmd_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x68 cmd_mode_cfg;<br>
> +<br>
> + cmd_mode_cfg.val = readl(®->CMD_MODE_CFG);<br>
> +<br>
> + cmd_mode_cfg.bits.gen_sw_0p_tx = enable;<br>
> + cmd_mode_cfg.bits.gen_sw_1p_tx = enable;<br>
> + cmd_mode_cfg.bits.gen_sw_2p_tx = enable;<br>
> + cmd_mode_cfg.bits.gen_lw_tx = enable;<br>
> + cmd_mode_cfg.bits.dcs_sw_0p_tx = enable;<br>
> + cmd_mode_cfg.bits.dcs_sw_1p_tx = enable;<br>
> + cmd_mode_cfg.bits.dcs_lw_tx = enable;<br>
> + cmd_mode_cfg.bits.max_rd_pkt_size = enable;<br>
> +<br>
> + cmd_mode_cfg.bits.gen_sr_0p_tx = enable;<br>
> + cmd_mode_cfg.bits.gen_sr_1p_tx = enable;<br>
> + cmd_mode_cfg.bits.gen_sr_2p_tx = enable;<br>
> + cmd_mode_cfg.bits.dcs_sr_0p_tx = enable;<br>
> +<br>
> + writel(cmd_mode_cfg.val, ®->CMD_MODE_CFG);<br>
> +}<br>
> +/*<br>
> + * Set DCS read command packet transmission to transmission type<br>
> + */<br>
> +void dsi_video_mode_lp_cmd_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x38 vid_mode_cfg;<br>
> +<br>
> + vid_mode_cfg.val = readl(®->VID_MODE_CFG);<br>
> + vid_mode_cfg.bits.lp_cmd_en = enable;<br>
> +<br>
> + writel(vid_mode_cfg.val, ®->VID_MODE_CFG);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Write command header in the generic interface (which also sends DCS commands) as a subset<br>
> + */<br>
> +void dsi_set_packet_header(struct dsi_context *ctx,<br>
> + u8 vc,<br>
> + u8 type,<br>
> + u8 wc_lsb,<br>
> + u8 wc_msb)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x6C gen_hdr;<br>
> +<br>
> + gen_hdr.bits.gen_dt = type;<br>
> + gen_hdr.bits.gen_vc = vc;<br>
> + gen_hdr.bits.gen_wc_lsbyte = wc_lsb;<br>
> + gen_hdr.bits.gen_wc_msbyte = wc_msb;<br>
> +<br>
> + writel(gen_hdr.val, ®->GEN_HDR);<br>
> +}<br>
> +/*<br>
> + * Write the payload of the long packet commands<br>
> + */<br>
> +void dsi_set_packet_payload(struct dsi_context *ctx, u32 payload)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(payload, ®->GEN_PLD_DATA);<br>
> +}<br>
> +/*<br>
> + * Read the payload of the long packet commands<br>
> + */<br>
> +u32 dsi_get_rx_payload(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + return readl(®->GEN_PLD_DATA);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Enable Bus Turn-around request<br>
> + */<br>
> +void dsi_bta_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(enable, ®->TA_EN);<br>
> +}<br>
> +/*<br>
> + * Enable EOTp reception<br>
> + */<br>
> +void dsi_eotp_rx_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xBC eotp_en;<br>
> +<br>
> + eotp_en.val = readl(®->EOTP_EN);<br>
> + eotp_en.bits.rx_eotp_en = enable;<br>
> +<br>
> + writel(eotp_en.val, ®->EOTP_EN);<br>
> +}<br>
> +/*<br>
> + * Enable EOTp transmission<br>
> + */<br>
> +void dsi_eotp_tx_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xBC eotp_en;<br>
> +<br>
> + eotp_en.val = readl(®->EOTP_EN);<br>
> + eotp_en.bits.tx_eotp_en = enable;<br>
> +<br>
> + writel(eotp_en.val, ®->EOTP_EN);<br>
> +}<br>
> +/*<br>
> + * Enable ECC reception, error correction and reporting<br>
> + */<br>
> +void dsi_ecc_rx_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xB4 rx_pkt_check_config;<br>
> +<br>
> + rx_pkt_check_config.val = readl(®->RX_PKT_CHECK_CONFIG);<br>
> + rx_pkt_check_config.bits.rx_pkt_ecc_en = enable;<br>
> +<br>
> + writel(rx_pkt_check_config.val, ®->RX_PKT_CHECK_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Enable CRC reception, error reporting<br>
> + */<br>
> +void dsi_crc_rx_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xB4 rx_pkt_check_config;<br>
> +<br>
> + rx_pkt_check_config.val = readl(®->RX_PKT_CHECK_CONFIG);<br>
> + rx_pkt_check_config.bits.rx_pkt_crc_en = enable;<br>
> +<br>
> + writel(rx_pkt_check_config.val, ®->RX_PKT_CHECK_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Get status of read command<br>
> + */<br>
> +bool dsi_is_bta_returned(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x98 cmd_mode_status;<br>
> +<br>
> + cmd_mode_status.val = readl(®->CMD_MODE_STATUS);<br>
> +<br>
> + return cmd_mode_status.bits.gen_cmd_rdcmd_done;<br>
> +}<br>
> +/*<br>
> + * Get the FULL status of generic read payload fifo<br>
> + */<br>
> +bool dsi_is_rx_payload_fifo_full(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x98 cmd_mode_status;<br>
> +<br>
> + cmd_mode_status.val = readl(®->CMD_MODE_STATUS);<br>
> +<br>
> + return cmd_mode_status.bits.gen_cmd_rdata_fifo_full;<br>
> +}<br>
> +/*<br>
> + * Get the EMPTY status of generic read payload fifo<br>
> + */<br>
> +bool dsi_is_rx_payload_fifo_empty(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x98 cmd_mode_status;<br>
> +<br>
> + cmd_mode_status.val = readl(®->CMD_MODE_STATUS);<br>
> +<br>
> + return cmd_mode_status.bits.gen_cmd_rdata_fifo_empty;<br>
> +}<br>
> +/*<br>
> + * Get the FULL status of generic write payload fifo<br>
> + */<br>
> +bool dsi_is_tx_payload_fifo_full(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x98 cmd_mode_status;<br>
> +<br>
> + cmd_mode_status.val = readl(®->CMD_MODE_STATUS);<br>
> +<br>
> + return cmd_mode_status.bits.gen_cmd_wdata_fifo_full;<br>
> +}<br>
> +/*<br>
> + * Get the EMPTY status of generic write payload fifo<br>
> + */<br>
> +bool dsi_is_tx_payload_fifo_empty(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x98 cmd_mode_status;<br>
> +<br>
> + cmd_mode_status.val = readl(®->CMD_MODE_STATUS);<br>
> +<br>
> + return cmd_mode_status.bits.gen_cmd_wdata_fifo_empty;<br>
> +}<br>
> +/*<br>
> + * Get the EMPTY status of generic command fifo<br>
> + */<br>
> +bool dsi_is_tx_cmd_fifo_empty(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x98 cmd_mode_status;<br>
> +<br>
> + cmd_mode_status.val = readl(®->CMD_MODE_STATUS);<br>
> +<br>
> + return cmd_mode_status.bits.gen_cmd_cmd_fifo_empty;<br>
> +}<br>
> +/*<br>
> + * DPI interface signal delay config<br>
> + * param byte_cycle period for waiting after controller receiving HSYNC from<br>
> + * DPI interface to start read pixel data from memory.<br>
> + */<br>
> +void dsi_dpi_sig_delay(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xD0 video_sig_delay_config;<br>
> +<br>
> + video_sig_delay_config.val = readl(®->VIDEO_SIG_DELAY_CONFIG);<br>
> + video_sig_delay_config.bits.video_sig_delay = byte_cycle;<br>
> +<br>
> + writel(video_sig_delay_config.val, ®->VIDEO_SIG_DELAY_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Configure how many cycles of byte clock would the PHY module take<br>
> + * to switch data lane from high speed to low power<br>
> + */<br>
> +void dsi_datalane_hs2lp_config(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xAC phy_datalane_time_config;<br>
> +<br>
> + phy_datalane_time_config.val = readl(®->PHY_DATALANE_TIME_CONFIG);<br>
> + phy_datalane_time_config.bits.phy_datalane_hs_to_lp_time = byte_cycle;<br>
> +<br>
> + writel(phy_datalane_time_config.val, ®->PHY_DATALANE_TIME_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Configure how many cycles of byte clock would the PHY module take<br>
> + * to switch the data lane from to low power high speed<br>
> + */<br>
> +void dsi_datalane_lp2hs_config(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xAC phy_datalane_time_config;<br>
> +<br>
> + phy_datalane_time_config.val = readl(®->PHY_DATALANE_TIME_CONFIG);<br>
> + phy_datalane_time_config.bits.phy_datalane_lp_to_hs_time = byte_cycle;<br>
> +<br>
> + writel(phy_datalane_time_config.val, ®->PHY_DATALANE_TIME_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Configure how many cycles of byte clock would the PHY module take<br>
> + * to switch clock lane from high speed to low power<br>
> + */<br>
> +void dsi_clklane_hs2lp_config(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xA8 phy_clklane_time_config;<br>
> +<br>
> + phy_clklane_time_config.val = readl(®->PHY_CLKLANE_TIME_CONFIG);<br>
> + phy_clklane_time_config.bits.phy_clklane_hs_to_lp_time = byte_cycle;<br>
> +<br>
> + writel(phy_clklane_time_config.val, ®->PHY_CLKLANE_TIME_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Configure how many cycles of byte clock would the PHY module take<br>
> + * to switch clock lane from to low power high speed<br>
> + */<br>
> +void dsi_clklane_lp2hs_config(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xA8 phy_clklane_time_config;<br>
> +<br>
> + phy_clklane_time_config.val = readl(®->PHY_CLKLANE_TIME_CONFIG);<br>
> + phy_clklane_time_config.bits.phy_clklane_lp_to_hs_time = byte_cycle;<br>
> +<br>
> + writel(phy_clklane_time_config.val, ®->PHY_CLKLANE_TIME_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Configure how many cycles of byte clock would the PHY module take<br>
> + * to turn the bus around to start receiving<br>
> + */<br>
> +void dsi_max_read_time(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(byte_cycle, ®->MAX_READ_TIME);<br>
> +}<br>
> +/*<br>
> + * Enable the automatic mechanism to stop providing clock in the clock<br>
> + * lane when time allows<br>
> + */<br>
> +void dsi_nc_clk_en(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x74 phy_clk_lane_lp_ctrl;<br>
> +<br>
> + phy_clk_lane_lp_ctrl.val = readl(®->PHY_CLK_LANE_LP_CTRL);<br>
> + phy_clk_lane_lp_ctrl.bits.auto_clklane_ctrl_en = enable;<br>
> +<br>
> + writel(phy_clk_lane_lp_ctrl.val, ®->PHY_CLK_LANE_LP_CTRL);<br>
> +}<br>
> +/*<br>
> + * Write transmission escape timeout<br>
> + * a safe guard so that the state machine would reset if transmission<br>
> + * takes too long<br>
> + */<br>
> +void dsi_tx_escape_division(struct dsi_context *ctx, u8 div)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(div, ®->TX_ESC_CLK_CONFIG);<br>
> +}<br>
> +/* <br>
> + * Configure timeout divisions (so they would have more clock ticks)<br>
> + * div no of hs cycles before transiting back to LP in<br>
> + * (lane_clk / div)<br>
> + */<br>
> +void dsi_timeout_clock_division(struct dsi_context *ctx, u8 div)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(div, ®->TIMEOUT_CNT_CLK_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Configure the Low power receive time out<br>
> + */<br>
> +void dsi_lp_rx_timeout(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(byte_cycle, ®->LRX_H_TO_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Configure a high speed transmission time out<br>
> + */<br>
> +void dsi_hs_tx_timeout(struct dsi_context *ctx, u16 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(byte_cycle, ®->HTX_TO_CONFIG);<br>
> +}<br>
> +/*<br>
> + * Get the error 0 interrupt register status<br>
> + */<br>
> +u32 dsi_int0_status(struct dsi_context *ctx)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x08 protocol_int_sts;<br>
> +<br>
> + protocol_int_sts.val = readl(®->PROTOCOL_INT_STS);<br>
> + writel(protocol_int_sts.val, ®->PROTOCOL_INT_CLR);<br>
> +<br>
> + if (protocol_int_sts.bits.dphy_errors_0)<br>
> + drm_err(dsi->drm, "dphy_err: escape entry error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.dphy_errors_1)<br>
> + drm_err(dsi->drm, "dphy_err: lp data transmission sync error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.dphy_errors_2)<br>
> + drm_err(dsi->drm, "dphy_err: control error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.dphy_errors_3)<br>
> + drm_err(dsi->drm, "dphy_err: LP0 contention error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.dphy_errors_4)<br>
> + drm_err(dsi->drm, "dphy_err: LP1 contention error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_0)<br>
> + drm_err(dsi->drm, "ack_err: SoT error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_1)<br>
> + drm_err(dsi->drm, "ack_err: SoT Sync error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_2)<br>
> + drm_err(dsi->drm, "ack_err: EoT Sync error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_3)<br>
> + drm_err(dsi->drm, "ack_err: Escape Mode Entry Command error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_4)<br>
> + drm_err(dsi->drm, "ack_err: LP Transmit Sync error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_5)<br>
> + drm_err(dsi->drm, "ack_err: Peripheral Timeout error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_6)<br>
> + drm_err(dsi->drm, "ack_err: False Control error\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_7)<br>
> + drm_err(dsi->drm, "ack_err: reserved (specific to device)\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_8)<br>
> + drm_err(dsi->drm, "ack_err: ECC error, single-bit (corrected)\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_9)<br>
> + drm_err(dsi->drm, "ack_err: ECC error, multi-bit (not corrected)\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_10)<br>
> + drm_err(dsi->drm, "ack_err: checksum error (long packet only)\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_11)<br>
> + drm_err(dsi->drm, "ack_err: not recognized DSI data type\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_12)<br>
> + drm_err(dsi->drm, "ack_err: DSI VC ID Invalid\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_13)<br>
> + drm_err(dsi->drm, "ack_err: invalid transmission length\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_14)<br>
> + drm_err(dsi->drm, "ack_err: reserved (specific to device)\n");<br>
> +<br>
> + if (protocol_int_sts.bits.ack_with_err_15)<br>
> + drm_err(dsi->drm, "ack_err: DSI protocol violation\n");<br>
> +<br>
> + return 0;<br>
> +}<br>
> +/*<br>
> + * Get the error 1 interrupt register status<br>
> + */<br>
> +u32 dsi_int1_status(struct dsi_context *ctx)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x10 internal_int_sts;<br>
> + u32 status = 0;<br>
> +<br>
> + internal_int_sts.val = readl(®->INTERNAL_INT_STS);<br>
> + writel(internal_int_sts.val, ®->INTERNAL_INT_CLR);<br>
> +<br>
> + if (internal_int_sts.bits.receive_pkt_size_err)<br>
> + drm_err(dsi->drm, "receive packet size error\n");<br>
> +<br>
> + if (internal_int_sts.bits.eotp_not_receive_err)<br>
> + drm_err(dsi->drm, "EoTp packet is not received\n");<br>
> +<br>
> + if (internal_int_sts.bits.gen_cmd_cmd_fifo_wr_err)<br>
> + drm_err(dsi->drm, "cmd header-fifo is full\n");<br>
> +<br>
> + if (internal_int_sts.bits.gen_cmd_rdata_fifo_rd_err)<br>
> + drm_err(dsi->drm, "cmd read-payload-fifo is empty\n");<br>
> +<br>
> + if (internal_int_sts.bits.gen_cmd_rdata_fifo_wr_err)<br>
> + drm_err(dsi->drm, "cmd read-payload-fifo is full\n");<br>
> +<br>
> + if (internal_int_sts.bits.gen_cmd_wdata_fifo_wr_err)<br>
> + drm_err(dsi->drm, "cmd write-payload-fifo is full\n");<br>
> +<br>
> + if (internal_int_sts.bits.gen_cmd_wdata_fifo_rd_err)<br>
> + drm_err(dsi->drm, "cmd write-payload-fifo is empty\n");<br>
> +<br>
> + if (internal_int_sts.bits.dpi_pix_fifo_wr_err) {<br>
> + drm_err(dsi->drm, "DPI pixel-fifo is full\n");<br>
> + status |= DSI_INT_STS_NEED_SOFT_RESET;<br>
> + }<br>
> +<br>
> + if (internal_int_sts.bits.ecc_single_err)<br>
> + drm_err(dsi->drm, "ECC single error in a received packet\n");<br>
> +<br>
> + if (internal_int_sts.bits.ecc_multi_err)<br>
> + drm_err(dsi->drm, "ECC multiple error in a received packet\n");<br>
> +<br>
> + if (internal_int_sts.bits.crc_err)<br>
> + drm_err(dsi->drm, "CRC error in the received packet payload\n");<br>
> +<br>
> + if (internal_int_sts.bits.hs_tx_timeout)<br>
> + drm_err(dsi->drm, "high-speed transmission timeout\n");<br>
> +<br>
> + if (internal_int_sts.bits.lp_rx_timeout)<br>
> + drm_err(dsi->drm, "low-power reception timeout\n");<br>
> +<br>
> + return status;<br>
> +}<br>
> +/*<br>
> + * Configure MASK (hiding) of interrupts coming from error 0 source<br>
> + */<br>
> +void dsi_int0_mask(struct dsi_context *ctx, u32 mask)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(mask, ®->MASK_PROTOCOL_INT);<br>
> +}<br>
> +/*<br>
> + * Configure MASK (hiding) of interrupts coming from error 1 source<br>
> + */<br>
> +void dsi_int1_mask(struct dsi_context *ctx, u32 mask)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(mask, ®->MASK_INTERNAL_INT);<br>
> +}<br>
> diff --git a/drivers/gpu/drm/sprd/dw_dsi_ctrl.h b/drivers/gpu/drm/sprd/dw_dsi_ctrl.h<br>
> new file mode 100644<br>
> index 0000000..ffba621<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dw_dsi_ctrl.h<br>
> @@ -0,0 +1,1475 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#ifndef _DW_DSI_CTRL_H_<br>
> +#define _DW_DSI_CTRL_H_<br>
> +<br>
> +#include <asm/types.h><br>
> +<br>
> +#include "sprd_dsi.h"<br>
> +<br>
> +struct dsi_reg {<br>
> + union _0x00 {<br>
> + u32 val;<br>
> + struct _DSI_VERSION {<br>
> + u32 dsi_version: 16;<br>
> + u32 reserved: 16;<br>
> + } bits;<br>
> + } DSI_VERSION;<br>
> +<br>
> + union _0x04 {<br>
> + u32 val;<br>
> + struct _SOFT_RESET {<br>
> + /*<br>
> + * This bit configures the core either to work normal or to<br>
> + * reset. It's default value is 0. After the core configur-<br>
> + * ation, to enable the mipi_dsi_host, set this register to 1.<br>
> + * 1: power up 0: reset core<br>
> + */<br>
> + u32 dsi_soft_reset: 1;<br>
> +<br>
> + u32 reserved: 31;<br>
> + } bits;<br>
> + } SOFT_RESET;<br>
> +<br>
> + union _0x08 {<br>
> + u32 val;<br>
> + struct _PROTOCOL_INT_STS {<br>
> + /* ErrEsc escape entry error from Lane 0 */<br>
> + u32 dphy_errors_0: 1;<br>
> +<br>
> + /* ErrSyncEsc low-power data transmission synchronization<br>
> + * error from Lane 0<br>
> + */<br>
> + u32 dphy_errors_1: 1;<br>
> +<br>
> + /* ErrControl error from Lane 0 */<br>
> + u32 dphy_errors_2: 1;<br>
> +<br>
> + /* ErrContentionLP0 LP0 contention error from Lane 0 */<br>
> + u32 dphy_errors_3: 1;<br>
> +<br>
> + /* ErrContentionLP1 LP1 contention error from Lane 0 */<br>
> + u32 dphy_errors_4: 1;<br>
> +<br>
> + /* debug mode protocol errors */<br>
> + u32 protocol_debug_err: 11;<br>
> +<br>
> + /* SoT error from the Acknowledge error report */<br>
> + u32 ack_with_err_0: 1;<br>
> +<br>
> + /* SoT Sync error from the Acknowledge error report */<br>
> + u32 ack_with_err_1: 1;<br>
> +<br>
> + /* EoT Sync error from the Acknowledge error report */<br>
> + u32 ack_with_err_2: 1;<br>
> +<br>
> + /* Escape Mode Entry Command error from the Acknowledge<br>
> + * error report<br>
> + */<br>
> + u32 ack_with_err_3: 1;<br>
> +<br>
> + /* LP Transmit Sync error from the Acknowledge error report */<br>
> + u32 ack_with_err_4: 1;<br>
> +<br>
> + /* Peripheral Timeout error from the Acknowledge error report */<br>
> + u32 ack_with_err_5: 1;<br>
> +<br>
> + /* False Control error from the Acknowledge error report */<br>
> + u32 ack_with_err_6: 1;<br>
> +<br>
> + /* reserved (specific to device) from the Acknowledge error<br>
> + * report<br>
> + */<br>
> + u32 ack_with_err_7: 1;<br>
> +<br>
> + /* ECC error, single-bit (detected and corrected) from the<br>
> + * Acknowledge error report<br>
> + */<br>
> + u32 ack_with_err_8: 1;<br>
> +<br>
> + /* ECC error, multi-bit (detected, not corrected) from the<br>
> + * Acknowledge error report<br>
> + */<br>
> + u32 ack_with_err_9: 1;<br>
> +<br>
> + /* checksum error (long packet only) from the Acknowledge<br>
> + * error report<br>
> + */<br>
> + u32 ack_with_err_10: 1;<br>
> +<br>
> + /* not recognized DSI data type from the Acknowledge error<br>
> + * report<br>
> + */<br>
> + u32 ack_with_err_11: 1;<br>
> +<br>
> + /* DSI VC ID Invalid from the Acknowledge error report */<br>
> + u32 ack_with_err_12: 1;<br>
> +<br>
> + /* invalid transmission length from the Acknowledge error<br>
> + * report<br>
> + */<br>
> + u32 ack_with_err_13: 1;<br>
> +<br>
> + /* reserved (specific to device) from the Acknowledge error<br>
> + * report<br>
> + */<br>
> + u32 ack_with_err_14: 1;<br>
> +<br>
> + /* DSI protocol violation from the Acknowledge error report */<br>
> + u32 ack_with_err_15: 1;<br>
> +<br>
> + } bits;<br>
> + } PROTOCOL_INT_STS;<br>
> +<br>
> + union _0x0C {<br>
> + u32 val;<br>
> + struct _MASK_PROTOCOL_INT {<br>
> + u32 mask_dphy_errors_0: 1;<br>
> + u32 mask_dphy_errors_1: 1;<br>
> + u32 mask_dphy_errors_2: 1;<br>
> + u32 mask_dphy_errors_3: 1;<br>
> + u32 mask_dphy_errors_4: 1;<br>
> + u32 mask_protocol_debug_err: 11;<br>
> + u32 mask_ack_with_err_0: 1;<br>
> + u32 mask_ack_with_err_1: 1;<br>
> + u32 mask_ack_with_err_2: 1;<br>
> + u32 mask_ack_with_err_3: 1;<br>
> + u32 mask_ack_with_err_4: 1;<br>
> + u32 mask_ack_with_err_5: 1;<br>
> + u32 mask_ack_with_err_6: 1;<br>
> + u32 mask_ack_with_err_7: 1;<br>
> + u32 mask_ack_with_err_8: 1;<br>
> + u32 mask_ack_with_err_9: 1;<br>
> + u32 mask_ack_with_err_10: 1;<br>
> + u32 mask_ack_with_err_11: 1;<br>
> + u32 mask_ack_with_err_12: 1;<br>
> + u32 mask_ack_with_err_13: 1;<br>
> + u32 mask_ack_with_err_14: 1;<br>
> + u32 mask_ack_with_err_15: 1;<br>
> + } bits;<br>
> + } MASK_PROTOCOL_INT;<br>
> +<br>
> + union _0x10 {<br>
> + u32 val;<br>
> + struct _INTERNAL_INT_STS {<br>
> + /* This bit indicates that the packet size error is detected<br>
> + * during the packet reception.<br>
> + */<br>
> + u32 receive_pkt_size_err: 1;<br>
> +<br>
> + /* This bit indicates that the EoTp packet is not received at<br>
> + * the end of the incoming peripheral transmission<br>
> + */<br>
> + u32 eotp_not_receive_err: 1;<br>
> +<br>
> + /* This bit indicates that the system tried to write a command<br>
> + * through the Generic interface and the FIFO is full. There-<br>
> + * fore, the command is not written.<br>
> + */<br>
> + u32 gen_cmd_cmd_fifo_wr_err: 1;<br>
> +<br>
> + /* This bit indicates that during a DCS read data, the payload<br>
> + * FIFO becomes empty and the data sent to the interface is<br>
> + * corrupted.<br>
> + */<br>
> + u32 gen_cmd_rdata_fifo_rd_err: 1;<br>
> +<br>
> + /* This bit indicates that during a generic interface packet<br>
> + * read back, the payload FIFO becomes full and the received<br>
> + * data is corrupted.<br>
> + */<br>
> + u32 gen_cmd_rdata_fifo_wr_err: 1;<br>
> +<br>
> + /* This bit indicates that the system tried to write a payload<br>
> + * data through the Generic interface and the FIFO is full.<br>
> + * Therefore, the payload is not written.<br>
> + */<br>
> + u32 gen_cmd_wdata_fifo_wr_err: 1;<br>
> +<br>
> + /* This bit indicates that during a Generic interface packet<br>
> + * build, the payload FIFO becomes empty and corrupt data is<br>
> + * sent.<br>
> + */<br>
> + u32 gen_cmd_wdata_fifo_rd_err: 1;<br>
> +<br>
> + /* This bit indicates that during a DPI pixel line storage,<br>
> + * the payload FIFO becomes full and the data stored is<br>
> + * corrupted.<br>
> + */<br>
> + u32 dpi_pix_fifo_wr_err: 1;<br>
> +<br>
> + /* internal debug error */<br>
> + u32 internal_debug_err: 19;<br>
> +<br>
> + /* This bit indicates that the ECC single error is detected<br>
> + * and corrected in a received packet.<br>
> + */<br>
> + u32 ecc_single_err: 1;<br>
> +<br>
> + /* This bit indicates that the ECC multiple error is detected<br>
> + * in a received packet.<br>
> + */<br>
> + u32 ecc_multi_err: 1;<br>
> +<br>
> + /* This bit indicates that the CRC error is detected in the<br>
> + * received packet payload.<br>
> + */<br>
> + u32 crc_err: 1;<br>
> +<br>
> + /* This bit indicates that the high-speed transmission timeout<br>
> + * counter reached the end and contention is detected.<br>
> + */<br>
> + u32 hs_tx_timeout: 1;<br>
> +<br>
> + /* This bit indicates that the low-power reception timeout<br>
> + * counter reached the end and contention is detected.<br>
> + */<br>
> + u32 lp_rx_timeout: 1;<br>
> +<br>
> + } bits;<br>
> + } INTERNAL_INT_STS;<br>
> +<br>
> + union _0x14 {<br>
> + u32 val;<br>
> + struct _MASK_INTERNAL_INT {<br>
> + u32 mask_receive_pkt_size_err: 1;<br>
> + u32 mask_eopt_not_receive_err: 1;<br>
> + u32 mask_gen_cmd_cmd_fifo_wr_err: 1;<br>
> + u32 mask_gen_cmd_rdata_fifo_rd_err: 1;<br>
> + u32 mask_gen_cmd_rdata_fifo_wr_err: 1;<br>
> + u32 mask_gen_cmd_wdata_fifo_wr_err: 1;<br>
> + u32 mask_gen_cmd_wdata_fifo_rd_err: 1;<br>
> + u32 mask_dpi_pix_fifo_wr_err: 1;<br>
> + u32 mask_internal_debug_err: 19;<br>
> + u32 mask_ecc_single_err: 1;<br>
> + u32 mask_ecc_multi_err: 1;<br>
> + u32 mask_crc_err: 1;<br>
> + u32 mask_hs_tx_timeout: 1;<br>
> + u32 mask_lp_rx_timeout: 1;<br>
> + } bits;<br>
> + } MASK_INTERNAL_INT;<br>
> +<br>
> + union _0x18 {<br>
> + u32 val;<br>
> + struct _DSI_MODE_CFG {<br>
> + /* This bit configures the operation mode<br>
> + * 0: Video mode ; 1: Command mode<br>
> + */<br>
> + u32 cmd_video_mode: 1;<br>
> +<br>
> + u32 reserved: 31;<br>
> +<br>
> + } bits;<br>
> + } DSI_MODE_CFG;<br>
> +<br>
> + union _0x1C {<br>
> + u32 val;<br>
> + struct _VIRTUAL_CHANNEL_ID {<br>
> + /* This field indicates the Generic interface read-back<br>
> + * virtual channel identification<br>
> + */<br>
> + u32 gen_rx_vcid: 2;<br>
> +<br>
> + /* This field configures the DPI virtual channel id that<br>
> + * is indexed to the VIDEO mode packets<br>
> + */<br>
> + u32 video_pkt_vcid: 2;<br>
> +<br>
> + u32 reserved: 28;<br>
> +<br>
> + } bits;<br>
> + } VIRTUAL_CHANNEL_ID;<br>
> +<br>
> + union _0x20 {<br>
> + u32 val;<br>
> + struct _DPI_VIDEO_FORMAT {<br>
> + /*<br>
> + * This field configures the DPI color coding as follows:<br>
> + * 0000: 16-bit configuration 1<br>
> + * 0001: 16-bit configuration 2<br>
> + * 0010: 16-bit configuration 3<br>
> + * 0011: 18-bit configuration 1<br>
> + * 0100: 18-bit configuration 2<br>
> + * 0101: 24-bit<br>
> + * 0110: 20-bit YCbCr 4:2:2 loosely packed<br>
> + * 0111: 24-bit YCbCr 4:2:2<br>
> + * 1000: 16-bit YCbCr 4:2:2<br>
> + * 1001: 30-bit<br>
> + * 1010: 36-bit<br>
> + * 1011: 12-bit YCbCr 4:2:0<br>
> + * 1100: Compression Display Stream<br>
> + * 1101-1111: 12-bit YCbCr 4:2:0<br>
> + */<br>
> + u32 dpi_video_mode_format: 6;<br>
> +<br>
> + /* When set to 1, this bit activates loosely packed<br>
> + * variant to 18-bit configurations<br>
> + */<br>
> + u32 loosely18_en: 1;<br>
> +<br>
> + u32 reserved: 25;<br>
> +<br>
> + } bits;<br>
> + } DPI_VIDEO_FORMAT;<br>
> +<br>
> + union _0x24 {<br>
> + u32 val;<br>
> + struct _VIDEO_PKT_CONFIG {<br>
> + /*<br>
> + * This field configures the number of pixels in a single<br>
> + * video packet. For 18-bit not loosely packed data types,<br>
> + * this number must be a multiple of 4. For YCbCr data<br>
> + * types, it must be a multiple of 2, as described in the<br>
> + * DSI specification.<br>
> + */<br>
> + u32 video_pkt_size: 16;<br>
> +<br>
> + /*<br>
> + * This register configures the number of chunks to be<br>
> + * transmitted during a Line period (a chunk consists of<br>
> + * a video packet and a null packet). If set to 0 or 1,<br>
> + * the video line is transmitted in a single packet. If<br>
> + * set to 1, the packet is part of a chunk, so a null packet<br>
> + * follows it if vid_null_size > 0. Otherwise, multiple chunks<br>
> + * are used to transmit each video line.<br>
> + */<br>
> + u32 video_line_chunk_num: 16;<br>
> +<br>
> + } bits;<br>
> + } VIDEO_PKT_CONFIG;<br>
> +<br>
> + union _0x28 {<br>
> + u32 val;<br>
> + struct _VIDEO_LINE_HBLK_TIME {<br>
> + /* This field configures the Horizontal Back Porch period<br>
> + * in lane byte clock cycles<br>
> + */<br>
> + u32 video_line_hbp_time: 16;<br>
> +<br>
> + /* This field configures the Horizontal Synchronism Active<br>
> + * period in lane byte clock cycles<br>
> + */<br>
> + u32 video_line_hsa_time: 16;<br>
> +<br>
> + } bits;<br>
> + } VIDEO_LINE_HBLK_TIME;<br>
> +<br>
> + union _0x2C {<br>
> + u32 val;<br>
> + struct _VIDEO_LINE_TIME {<br>
> + /* This field configures the size of the total line time<br>
> + * (HSA+HBP+HACT+HFP) counted in lane byte clock cycles<br>
> + */<br>
> + u32 video_line_time: 16;<br>
> +<br>
> + u32 reserved: 16;<br>
> +<br>
> + } bits;<br>
> + } VIDEO_LINE_TIME;<br>
> +<br>
> + union _0x30 {<br>
> + u32 val;<br>
> + struct _VIDEO_VBLK_LINES {<br>
> + /* This field configures the Vertical Front Porch period<br>
> + * measured in number of horizontal lines<br>
> + */<br>
> + u32 vfp_lines: 10;<br>
> +<br>
> + /* This field configures the Vertical Back Porch period<br>
> + * measured in number of horizontal lines<br>
> + */<br>
> + u32 vbp_lines: 10;<br>
> +<br>
> + /* This field configures the Vertical Synchronism Active<br>
> + * period measured in number of horizontal lines<br>
> + */<br>
> + u32 vsa_lines: 10;<br>
> +<br>
> + u32 reserved: 2;<br>
> +<br>
> + } bits;<br>
> + } VIDEO_VBLK_LINES;<br>
> +<br>
> + union _0x34 {<br>
> + u32 val;<br>
> + struct _VIDEO_VACTIVE_LINES {<br>
> + /* This field configures the Vertical Active period measured<br>
> + * in number of horizontal lines<br>
> + */<br>
> + u32 vactive_lines: 14;<br>
> +<br>
> + u32 reserved: 18;<br>
> +<br>
> + } bits;<br>
> + } VIDEO_VACTIVE_LINES;<br>
> +<br>
> + union _0x38 {<br>
> + u32 val;<br>
> + struct _VID_MODE_CFG {<br>
> + /*<br>
> + * This field indicates the video mode transmission type as<br>
> + * follows:<br>
> + * 00: Non-burst with sync pulses<br>
> + * 01: Non-burst with sync events<br>
> + * 10 and 11: Burst mode<br>
> + */<br>
> + u32 vid_mode_type: 2;<br>
> +<br>
> + u32 reserved_0: 6;<br>
> +<br>
> + /* When set to 1, this bit enables the return to low-power<br>
> + * inside the VSA period when timing allows.<br>
> + */<br>
> + u32 lp_vsa_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the return to low-power<br>
> + * inside the VBP period when timing allows.<br>
> + */<br>
> + u32 lp_vbp_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the return to low-power<br>
> + * inside the VFP period when timing allows.<br>
> + */<br>
> + u32 lp_vfp_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the return to low-power<br>
> + * inside the VACT period when timing allows.<br>
> + */<br>
> + u32 lp_vact_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the return to low-power<br>
> + * inside the HBP period when timing allows.<br>
> + */<br>
> + u32 lp_hbp_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the return to low-power<br>
> + * inside the HFP period when timing allows.<br>
> + */<br>
> + u32 lp_hfp_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the request for an ack-<br>
> + * nowledge response at the end of a frame.<br>
> + */<br>
> + u32 frame_bta_ack_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the command transmission<br>
> + * only in low-power mode.<br>
> + */<br>
> + u32 lp_cmd_en: 1;<br>
> +<br>
> + u32 reserved_1: 16;<br>
> +<br>
> + } bits;<br>
> + } VID_MODE_CFG;<br>
> +<br>
> + union _0x3C {<br>
> + u32 val;<br>
> + struct _SDF_MODE_CONFIG {<br>
> + /*<br>
> + * This field defines the 3D mode on/off & display orientation:<br>
> + * 00: 3D mode off (2D mode on)<br>
> + * 01: 3D mode on, portrait orientation<br>
> + * 10: 3D mode on, landscape orientation<br>
> + * 11: Reserved<br>
> + */<br>
> + u32 rf_3d_mode: 2;<br>
> +<br>
> + /*<br>
> + * This field defines the 3D image format:<br>
> + * 00: Line (alternating lines of left and right data)<br>
> + * 01: Frame (alternating frames of left and right data)<br>
> + * 10: Pixel (alternating pixels of left and right data)<br>
> + * 11: Reserved<br>
> + */<br>
> + u32 rf_3d_format: 2;<br>
> +<br>
> + /*<br>
> + * This field defines whether there is a second VSYNC pulse<br>
> + * between Left and Right Images, when 3D Image Format is<br>
> + * Frame-based:<br>
> + * 0: No sync pulses between left and right data<br>
> + * 1: Sync pulse (HSYNC, VSYNC, blanking) between left and<br>
> + * right data<br>
> + */<br>
> + u32 second_vsync_en: 1;<br>
> +<br>
> + /*<br>
> + * This bit defines the left or right order:<br>
> + * 0: Left eye data is sent first, and then the right eye data<br>
> + * is sent.<br>
> + * 1: Right eye data is sent first, and then the left eye data<br>
> + * is sent.<br>
> + */<br>
> + u32 left_right_order: 1;<br>
> +<br>
> + u32 reserved_0: 2;<br>
> +<br>
> + /*<br>
> + * When set, causes the next VSS packet to include 3D control<br>
> + * payload in every VSS packet.<br>
> + */<br>
> + u32 rf_3d_payload_en: 1;<br>
> +<br>
> + u32 reserved_1: 23;<br>
> +<br>
> + } bits;<br>
> + } SDF_MODE_CONFIG;<br>
> +<br>
> + union _0x40 {<br>
> + u32 val;<br>
> + struct _TIMEOUT_CNT_CLK_CONFIG {<br>
> + /*<br>
> + * This field indicates the division factor for the Time Out<br>
> + * clock used as the timing unit in the configuration of HS to<br>
> + * LP and LP to HS transition error.<br>
> + */<br>
> + u32 timeout_cnt_clk_config: 16;<br>
> +<br>
> + u32 reserved: 16;<br>
> +<br>
> + } bits;<br>
> + } TIMEOUT_CNT_CLK_CONFIG;<br>
> +<br>
> + union _0x44 {<br>
> + u32 val;<br>
> + struct _HTX_TO_CONFIG {<br>
> + /*<br>
> + * This field configures the timeout counter that triggers<br>
> + * a high speed transmission timeout contention detection<br>
> + * (measured in TO_CLK_DIVISION cycles).<br>
> + *<br>
> + * If using the non-burst mode and there is no sufficient<br>
> + * time to switch from HS to LP and back in the period which<br>
> + * is from one line data finishing to the next line sync<br>
> + * start, the DSI link returns the LP state once per frame,<br>
> + * then you should configure the TO_CLK_DIVISION and<br>
> + * hstx_to_cnt to be in accordance with:<br>
> + * hstx_to_cnt * lanebyteclkperiod * TO_CLK_DIVISION >= the<br>
> + * time of one FRAME data transmission * (1 + 10%)<br>
> + *<br>
> + * In burst mode, RGB pixel packets are time-compressed,<br>
> + * leaving more time during a scan line. Therefore, if in<br>
> + * burst mode and there is sufficient time to switch from HS<br>
> + * to LP and back in the period of time from one line data<br>
> + * finishing to the next line sync start, the DSI link can<br>
> + * return LP mode and back in this time interval to save power.<br>
> + * For this, configure the TO_CLK_DIVISION and hstx_to_cnt<br>
> + * to be in accordance with:<br>
> + * hstx_to_cnt * lanebyteclkperiod * TO_CLK_DIVISION >= the<br>
> + * time of one LINE data transmission * (1 + 10%)<br>
> + */<br>
> + u32 htx_to_cnt_limit: 32;<br>
> + } bits;<br>
> + } HTX_TO_CONFIG;<br>
> +<br>
> + union _0x48 {<br>
> + u32 val;<br>
> + struct _LRX_H_TO_CONFIG {<br>
> + /*<br>
> + * This field configures the timeout counter that triggers<br>
> + * a low-power reception timeout contention detection (measured<br>
> + * in TO_CLK_DIVISION cycles).<br>
> + */<br>
> + u32 lrx_h_to_cnt_limit: 32;<br>
> + } bits;<br>
> + } LRX_H_TO_CONFIG;<br>
> +<br>
> + union _0x4C {<br>
> + u32 val;<br>
> + struct _RD_PRESP_TO_CONFIG {<br>
> + /*<br>
> + * This field sets a period for which the DWC_mipi_dsi_host<br>
> + * keeps the link still, after sending a low-power read oper-<br>
> + * ation. This period is measured in cycles of lanebyteclk.<br>
> + * The counting starts when the D-PHY enters the Stop state<br>
> + * and causes no interrupts.<br>
> + */<br>
> + u32 lprd_presp_to_cnt_limit: 16;<br>
> +<br>
> + /*<br>
> + * This field sets a period for which the DWC_mipi_dsi_host<br>
> + * keeps the link still, after sending a high-speed read oper-<br>
> + * ation. This period is measured in cycles of lanebyteclk.<br>
> + * The counting starts when the D-PHY enters the Stop state<br>
> + * and causes no interrupts.<br>
> + */<br>
> + u32 hsrd_presp_to_cnt_limit: 16;<br>
> +<br>
> + } bits;<br>
> + } RD_PRESP_TO_CONFIG;<br>
> +<br>
> + union _0x50 {<br>
> + u32 val;<br>
> + struct _HSWR_PRESP_TO_CONFIG {<br>
> + /*<br>
> + * This field sets a period for which the DWC_mipi_dsi_host<br>
> + * keeps the link inactive after sending a high-speed write<br>
> + * operation. This period is measured in cycles of lanebyteclk.<br>
> + * The counting starts when the D-PHY enters the Stop state<br>
> + * and causes no interrupts.<br>
> + */<br>
> + u32 hswr_presp_to_cnt_limit: 16;<br>
> +<br>
> + u32 reserved_0: 8;<br>
> +<br>
> + /*<br>
> + * When set to 1, this bit ensures that the peripheral response<br>
> + * timeout caused by hs_wr_to_cnt is used only once per eDPI<br>
> + * frame, when both the following conditions are met:<br>
> + * dpivsync_edpiwms has risen and fallen.<br>
> + * Packets originated from eDPI have been transmitted and its<br>
> + * FIFO is empty again In this scenario no non-eDPI requests<br>
> + * are sent to the D-PHY, even if there is traffic from generic<br>
> + * or DBI ready to be sent, making it return to stop state.<br>
> + * When it does so, PRESP_TO counter is activated and only when<br>
> + * it finishes does the controller send any other traffic that<br>
> + * is ready.<br>
> + */<br>
> + u32 hswr_presp_to_mode: 1;<br>
> +<br>
> + u32 reserved_1: 7;<br>
> +<br>
> + } bits;<br>
> + } HSWR_PRESP_TO_CONFIG;<br>
> +<br>
> + union _0x54 {<br>
> + u32 val;<br>
> + struct _LPWR_PRESP_TO_CONFIG {<br>
> + /*<br>
> + * This field sets a period for which the DWC_mipi_dsi_host<br>
> + * keeps the link still, after sending a low-power write oper-<br>
> + * ation. This period is measured in cycles of lanebyteclk.<br>
> + * The counting starts when the D-PHY enters the Stop state<br>
> + * and causes no interrupts.<br>
> + */<br>
> + u32 lpwr_presp_to_cnt_limit: 16;<br>
> +<br>
> + u32 reserved: 16;<br>
> +<br>
> + } bits;<br>
> + } LPWR_PRESP_TO_CONFIG;<br>
> +<br>
> + union _0x58 {<br>
> + u32 val;<br>
> + struct _BTA_PRESP_TO_CONFIG {<br>
> + /*<br>
> + * This field sets a period for which the DWC_mipi_dsi_host<br>
> + * keeps the link still, after completing a Bus Turn-Around.<br>
> + * This period is measured in cycles of lanebyteclk. The<br>
> + * counting starts when the D-PHY enters the Stop state and<br>
> + * causes no interrupts.<br>
> + */<br>
> + u32 bta_presp_to_cnt_limit: 16;<br>
> +<br>
> + u32 reserved: 16;<br>
> +<br>
> + } bits;<br>
> + } BTA_PRESP_TO_CONFIG;<br>
> +<br>
> + union _0x5C {<br>
> + u32 val;<br>
> + struct _TX_ESC_CLK_CONFIG {<br>
> + /*<br>
> + * This field indicates the division factor for the TX Escape<br>
> + * clock source (lanebyteclk). The values 0 and 1 stop the<br>
> + * TX_ESC clock generation.<br>
> + */<br>
> + u32 tx_esc_clk_config: 16;<br>
> +<br>
> + u32 reserved: 16;<br>
> +<br>
> + } bits;<br>
> + } TX_ESC_CLK_CONFIG;<br>
> +<br>
> + union _0x60 {<br>
> + u32 val;<br>
> + struct _VACT_CMD_TRANS_LIMIT {<br>
> + /*<br>
> + * This field is used for the transmission of commands in<br>
> + * low-power mode. It defines the size, in bytes, of the<br>
> + * largest packet that can fit in a line during the VACT<br>
> + * region.<br>
> + */<br>
> + u32 vact_cmd_trans_limit: 8;<br>
> +<br>
> + u32 reserved: 24;<br>
> +<br>
> + } bits;<br>
> + } VACT_CMD_TRANS_LIMIT;<br>
> +<br>
> + union _0x64 {<br>
> + u32 val;<br>
> + struct _VBLK_CMD_TRANS_LIMIT {<br>
> + /*<br>
> + * This field is used for the transmission of commands in<br>
> + * low-power mode. It defines the size, in bytes, of the<br>
> + * largest packet that can fit in a line during the VSA, VBP,<br>
> + * and VFP regions.<br>
> + */<br>
> + u32 vblk_cmd_trans_limit: 8;<br>
> +<br>
> + u32 reserved: 24;<br>
> +<br>
> + } bits;<br>
> + } VBLK_CMD_TRANS_LIMIT;<br>
> +<br>
> + union _0x68 {<br>
> + u32 val;<br>
> + struct _CMD_MODE_CFG {<br>
> + /*<br>
> + * When set to 1, this bit enables the tearing effect<br>
> + * acknowledge request.<br>
> + */<br>
> + u32 tear_fx_en: 1;<br>
> +<br>
> + /*<br>
> + * When set to 1, this bit enables the acknowledge request<br>
> + * after each packet transmission.<br>
> + */<br>
> + u32 ack_rqst_en: 1;<br>
> +<br>
> + u32 reserved_0: 3;<br>
> +<br>
> + u32 pps_tx: 1;<br>
> + u32 exq_tx: 1;<br>
> + u32 cmc_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the Generic short write packet with<br>
> + * zero parameter command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 gen_sw_0p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the Generic short write packet with<br>
> + * one parameter command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 gen_sw_1p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the Generic short write packet with<br>
> + * two parameters command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 gen_sw_2p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the Generic short read packet with<br>
> + * zero parameter command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 gen_sr_0p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the Generic short read packet with<br>
> + * one parameter command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 gen_sr_1p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the Generic short read packet with<br>
> + * two parameters command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 gen_sr_2p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the Generic long write packet command<br>
> + * transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 gen_lw_tx: 1;<br>
> +<br>
> + u32 reserved_1: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the DCS short write packet with zero<br>
> + * parameter command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 dcs_sw_0p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the DCS short write packet with one<br>
> + * parameter command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 dcs_sw_1p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the DCS short read packet with zero<br>
> + * parameter command transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 dcs_sr_0p_tx: 1;<br>
> +<br>
> + /*<br>
> + * This bit configures the DCS long write packet command<br>
> + * transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 dcs_lw_tx: 1;<br>
> +<br>
> + u32 reserved_2: 4;<br>
> +<br>
> + /*<br>
> + * This bit configures the maximum read packet size command<br>
> + * transmission type:<br>
> + * 0: High-speed 1: Low-power<br>
> + */<br>
> + u32 max_rd_pkt_size: 1;<br>
> +<br>
> + u32 reserved_3: 7;<br>
> +<br>
> + } bits;<br>
> + } CMD_MODE_CFG;<br>
> +<br>
> + union _0x6C {<br>
> + u32 val;<br>
> + struct _GEN_HDR {<br>
> + /*<br>
> + * This field configures the packet data type of the header<br>
> + * packet.<br>
> + */<br>
> + u32 gen_dt: 6;<br>
> +<br>
> + /*<br>
> + * This field configures the virtual channel id of the header<br>
> + * packet.<br>
> + */<br>
> + u32 gen_vc: 2;<br>
> +<br>
> + /*<br>
> + * This field configures the least significant byte of the<br>
> + * header packet's Word count for long packets or data 0 for<br>
> + * short packets.<br>
> + */<br>
> + u32 gen_wc_lsbyte: 8;<br>
> +<br>
> + /*<br>
> + * This field configures the most significant byte of the<br>
> + * header packet's word count for long packets or data 1 for<br>
> + * short packets.<br>
> + */<br>
> + u32 gen_wc_msbyte: 8;<br>
> +<br>
> + u32 reserved: 8;<br>
> +<br>
> + } bits;<br>
> + } GEN_HDR;<br>
> +<br>
> + union _0x70 {<br>
> + u32 val;<br>
> + struct _GEN_PLD_DATA {<br>
> + /* This field indicates byte 1 of the packet payload. */<br>
> + u32 gen_pld_b1: 8;<br>
> +<br>
> + /* This field indicates byte 2 of the packet payload. */<br>
> + u32 gen_pld_b2: 8;<br>
> +<br>
> + /* This field indicates byte 3 of the packet payload. */<br>
> + u32 gen_pld_b3: 8;<br>
> +<br>
> + /* This field indicates byte 4 of the packet payload. */<br>
> + u32 gen_pld_b4: 8;<br>
> +<br>
> + } bits;<br>
> + } GEN_PLD_DATA;<br>
> +<br>
> + union _0x74 {<br>
> + u32 val;<br>
> + struct _PHY_CLK_LANE_LP_CTRL {<br>
> + /* This bit controls the D-PHY PPI txrequestclkhs signal */<br>
> + u32 phy_clklane_tx_req_hs: 1;<br>
> +<br>
> + /* This bit enables the automatic mechanism to stop providing<br>
> + * clock in the clock lane when time allows.<br>
> + */<br>
> + u32 auto_clklane_ctrl_en: 1;<br>
> +<br>
> + u32 reserved: 30;<br>
> + } bits;<br>
> + } PHY_CLK_LANE_LP_CTRL;<br>
> +<br>
> + union _0x78 {<br>
> + u32 val;<br>
> + struct _PHY_INTERFACE_CTRL {<br>
> + /* When set to 0, this bit places the D-PHY macro in power-<br>
> + * down state.<br>
> + */<br>
> + u32 rf_phy_shutdown: 1;<br>
> +<br>
> + /* When set to 0, this bit places the digital section of the<br>
> + * D-PHY in the reset state.<br>
> + */<br>
> + u32 rf_phy_reset_n: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the D-PHY Clock Lane<br>
> + * module.<br>
> + */<br>
> + u32 rf_phy_clk_en: 1;<br>
> +<br>
> + /* When the D-PHY is in ULPS, this bit enables the D-PHY PLL. */<br>
> + u32 rf_phy_force_pll: 1;<br>
> +<br>
> + /* ULPS mode Request on clock lane */<br>
> + u32 rf_phy_clk_txrequlps: 1;<br>
> +<br>
> + /* ULPS mode Exit on clock lane */<br>
> + u32 rf_phy_clk_txexitulps: 1;<br>
> +<br>
> + /* ULPS mode Request on all active data lanes */<br>
> + u32 rf_phy_data_txrequlps: 1;<br>
> +<br>
> + /* ULPS mode Exit on all active data lanes */<br>
> + u32 rf_phy_data_txexitulps: 1;<br>
> +<br>
> + u32 reserved: 24;<br>
> + } bits;<br>
> + } PHY_INTERFACE_CTRL;<br>
> +<br>
> + union _0x7C {<br>
> + u32 val;<br>
> + struct _PHY_TX_TRIGGERS {<br>
> + /* This field controls the trigger transmissions. */<br>
> + u32 phy_tx_triggers: 4;<br>
> +<br>
> + u32 reserved: 28;<br>
> + } bits;<br>
> + } PHY_TX_TRIGGERS;<br>
> +<br>
> + union _0x80 {<br>
> + u32 val;<br>
> + struct _DESKEW_START {<br>
> + u32 deskew_start: 1;<br>
> + u32 reserved: 31;<br>
> + } bits;<br>
> + } DESKEW_START;<br>
> +<br>
> + union _0x84 {<br>
> + u32 val;<br>
> + struct _DESKEW_MODE {<br>
> + u32 deskew_mode: 2;<br>
> + u32 reserved: 30;<br>
> + } bits;<br>
> + } DESKEW_MODE;<br>
> +<br>
> + union _0x88 {<br>
> + u32 val;<br>
> + struct _DESKEW_TIME {<br>
> + u32 deskew_time: 32;<br>
> + } bits;<br>
> + } DESKEW_TIME;<br>
> +<br>
> + union _0x8C {<br>
> + u32 val;<br>
> + struct _DESKEW_PERIOD {<br>
> + u32 deskew_period: 32;<br>
> + } bits;<br>
> + } DESKEW_PERIOD;<br>
> +<br>
> + union _0x90 {<br>
> + u32 val;<br>
> + struct _DESKEW_BUSY {<br>
> + u32 deskew_busy: 1;<br>
> + u32 reserved: 31;<br>
> + } bits;<br>
> + } DESKEW_BUSY;<br>
> +<br>
> + union _0x94 {<br>
> + u32 val;<br>
> + struct _DESKEW_LANE_MASK {<br>
> + u32 deskew_lane0_mask: 1;<br>
> + u32 deskew_lane1_mask: 1;<br>
> + u32 deskew_lane2_mask: 1;<br>
> + u32 deskew_lane3_mask: 1;<br>
> + u32 reserved: 28;<br>
> + } bits;<br>
> + } DESKEW_LANE_MASK;<br>
> +<br>
> + union _0x98 {<br>
> + u32 val;<br>
> + struct _CMD_MODE_STATUS {<br>
> + /*<br>
> + * This bit is set when a read command is issued and cleared<br>
> + * when the entire response is stored in the FIFO.<br>
> + * Value after reset: 0x0<br>
> + *<br>
> + * NOTE:<br>
> + * For mipi-dsi-r1p0 IP, this bit is set immediately when<br>
> + * the read cmd is set to the GEN_HDR register.<br>
> + *<br>
> + * For dsi-ctrl-r1p0 IP, this bit is set only after the read<br>
> + * cmd was actually sent out from the controller.<br>
> + */<br>
> + u32 gen_cmd_rdcmd_ongoing: 1;<br>
> +<br>
> + /*<br>
> + * This bit indicates the empty status of the generic read<br>
> + * payload FIFO.<br>
> + * Value after reset: 0x1<br>
> + */<br>
> + u32 gen_cmd_rdata_fifo_empty: 1;<br>
> +<br>
> + /*<br>
> + * This bit indicates the full status of the generic read<br>
> + * payload FIFO.<br>
> + * Value after reset: 0x0<br>
> + */<br>
> + u32 gen_cmd_rdata_fifo_full: 1;<br>
> +<br>
> + /*<br>
> + * This bit indicates the empty status of the generic write<br>
> + * payload FIFO.<br>
> + * Value after reset: 0x1<br>
> + */<br>
> + u32 gen_cmd_wdata_fifo_empty: 1;<br>
> +<br>
> + /*<br>
> + * This bit indicates the full status of the generic write<br>
> + * payload FIFO.<br>
> + * Value after reset: 0x0<br>
> + */<br>
> + u32 gen_cmd_wdata_fifo_full: 1;<br>
> +<br>
> + /*<br>
> + * This bit indicates the empty status of the generic<br>
> + * command FIFO.<br>
> + * Value after reset: 0x1<br>
> + */<br>
> + u32 gen_cmd_cmd_fifo_empty: 1;<br>
> +<br>
> + /*<br>
> + * This bit indicates the full status of the generic<br>
> + * command FIFO.<br>
> + * Value after reset: 0x0<br>
> + */<br>
> + u32 gen_cmd_cmd_fifo_full: 1;<br>
> +<br>
> + /*<br>
> + * This bit is set when the entire response of read is<br>
> + * stored in the rx payload FIFO. And it will be cleared<br>
> + * automaticlly after read this bit each time.<br>
> + * Value after reset: 0x0<br>
> + *<br>
> + * NOTE: this bit is just supported for dsi-ctrl-r1p0 IP<br>
> + */<br>
> + u32 gen_cmd_rdcmd_done: 1;<br>
> +<br>
> + u32 reserved : 24;<br>
> +<br>
> + } bits;<br>
> + } CMD_MODE_STATUS;<br>
> +<br>
> + union _0x9C {<br>
> + u32 val;<br>
> + struct _PHY_STATUS {<br>
> + /* the status of phydirection D-PHY signal */<br>
> + u32 phy_direction: 1;<br>
> +<br>
> + /* the status of phylock D-PHY signal */<br>
> + u32 phy_lock: 1;<br>
> +<br>
> + /* the status of rxulpsesc0lane D-PHY signal */<br>
> + u32 phy_rxulpsesc0lane: 1;<br>
> +<br>
> + /* the status of phystopstateclklane D-PHY signal */<br>
> + u32 phy_stopstateclklane: 1;<br>
> +<br>
> + /* the status of phystopstate0lane D-PHY signal */<br>
> + u32 phy_stopstate0lane: 1;<br>
> +<br>
> + /* the status of phystopstate1lane D-PHY signal */<br>
> + u32 phy_stopstate1lane: 1;<br>
> +<br>
> + /* the status of phystopstate2lane D-PHY signal */<br>
> + u32 phy_stopstate2lane: 1;<br>
> +<br>
> + /* the status of phystopstate3lane D-PHY signal */<br>
> + u32 phy_stopstate3lane: 1;<br>
> +<br>
> + /* the status of phyulpsactivenotclk D-PHY signal */<br>
> + u32 phy_ulpsactivenotclk: 1;<br>
> +<br>
> + /* the status of ulpsactivenot0lane D-PHY signal */<br>
> + u32 phy_ulpsactivenot0lane: 1;<br>
> +<br>
> + /* the status of ulpsactivenot1lane D-PHY signal */<br>
> + u32 phy_ulpsactivenot1lane: 1;<br>
> +<br>
> + /* the status of ulpsactivenot2lane D-PHY signal */<br>
> + u32 phy_ulpsactivenot2lane: 1;<br>
> +<br>
> + /* the status of ulpsactivenot3lane D-PHY signal */<br>
> + u32 phy_ulpsactivenot3lane: 1;<br>
> +<br>
> + u32 reserved: 19;<br>
> +<br>
> + } bits;<br>
> + } PHY_STATUS;<br>
> +<br>
> + union _0xA0 {<br>
> + u32 val;<br>
> + struct _PHY_MIN_STOP_TIME {<br>
> + /* This field configures the minimum wait period to request<br>
> + * a high-speed transmission after the Stop state.<br>
> + */<br>
> + u32 phy_min_stop_time: 8;<br>
> +<br>
> + u32 reserved: 24;<br>
> + } bits;<br>
> + } PHY_MIN_STOP_TIME;<br>
> +<br>
> + union _0xA4 {<br>
> + u32 val;<br>
> + struct _PHY_LANE_NUM_CONFIG {<br>
> + /*<br>
> + * This field configures the number of active data lanes:<br>
> + * 00: One data lane (lane 0)<br>
> + * 01: Two data lanes (lanes 0 and 1)<br>
> + * 10: Three data lanes (lanes 0, 1, and 2)<br>
> + * 11: Four data lanes (lanes 0, 1, 2, and 3)<br>
> + */<br>
> + u32 phy_lane_num: 2;<br>
> +<br>
> + u32 reserved: 30;<br>
> +<br>
> + } bits;<br>
> + } PHY_LANE_NUM_CONFIG;<br>
> +<br>
> + union _0xA8 {<br>
> + u32 val;<br>
> + struct _PHY_CLKLANE_TIME_CONFIG {<br>
> + /*<br>
> + * This field configures the maximum time that the D-PHY<br>
> + * clock lane takes to go from low-power to high-speed<br>
> + * transmission measured in lane byte clock cycles.<br>
> + */<br>
> + u32 phy_clklane_lp_to_hs_time: 16;<br>
> +<br>
> + /*<br>
> + * This field configures the maximum time that the D-PHY<br>
> + * clock lane takes to go from high-speed to low-power<br>
> + * transmission measured in lane byte clock cycles.<br>
> + */<br>
> + u32 phy_clklane_hs_to_lp_time: 16;<br>
> +<br>
> + } bits;<br>
> + } PHY_CLKLANE_TIME_CONFIG;<br>
> +<br>
> + union _0xAC {<br>
> + u32 val;<br>
> + struct _PHY_DATALANE_TIME_CONFIG {<br>
> + /*<br>
> + * This field configures the maximum time that the D-PHY data<br>
> + * lanes take to go from low-power to high-speed transmission<br>
> + * measured in lane byte clock cycles.<br>
> + */<br>
> + u32 phy_datalane_lp_to_hs_time: 16;<br>
> +<br>
> + /*<br>
> + * This field configures the maximum time that the D-PHY data<br>
> + * lanes take to go from high-speed to low-power transmission<br>
> + * measured in lane byte clock cycles.<br>
> + */<br>
> + u32 phy_datalane_hs_to_lp_time: 16;<br>
> +<br>
> + } bits;<br>
> + } PHY_DATALANE_TIME_CONFIG;<br>
> +<br>
> + union _0xB0 {<br>
> + u32 val;<br>
> + struct _MAX_READ_TIME {<br>
> + /*<br>
> + * This field configures the maximum time required to perform<br>
> + * a read command in lane byte clock cycles. This register can<br>
> + * only be modified when no read command is in progress.<br>
> + */<br>
> + u32 max_rd_time: 16;<br>
> +<br>
> + u32 reserved: 16;<br>
> +<br>
> + } bits;<br>
> + } MAX_READ_TIME;<br>
> +<br>
> + union _0xB4 {<br>
> + u32 val;<br>
> + struct _RX_PKT_CHECK_CONFIG {<br>
> + /* When set to 1, this bit enables the ECC reception, error<br>
> + * correction, and reporting.<br>
> + */<br>
> + u32 rx_pkt_ecc_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the CRC reception and error<br>
> + * reporting.<br>
> + */<br>
> + u32 rx_pkt_crc_en: 1;<br>
> +<br>
> + u32 reserved: 30;<br>
> +<br>
> + } bits;<br>
> + } RX_PKT_CHECK_CONFIG;<br>
> +<br>
> + union _0xB8 {<br>
> + u32 val;<br>
> + struct _TA_EN {<br>
> + /* When set to 1, this bit enables the Bus Turn-Around (BTA)<br>
> + * request.<br>
> + */<br>
> + u32 ta_en: 1;<br>
> +<br>
> + u32 reserved: 31;<br>
> +<br>
> + } bits;<br>
> + } TA_EN;<br>
> +<br>
> + union _0xBC {<br>
> + u32 val;<br>
> + struct _EOTP_EN {<br>
> + /* When set to 1, this bit enables the EoTp transmission */<br>
> + u32 tx_eotp_en: 1;<br>
> +<br>
> + /* When set to 1, this bit enables the EoTp reception. */<br>
> + u32 rx_eotp_en: 1;<br>
> +<br>
> + u32 reserved: 30;<br>
> +<br>
> + } bits;<br>
> + } EOTP_EN;<br>
> +<br>
> + union _0xC0 {<br>
> + u32 val;<br>
> + struct _VIDEO_NULLPKT_SIZE {<br>
> + /*<br>
> + * This register configures the number of bytes inside a null<br>
> + * packet. Setting it to 0 disables the null packets.<br>
> + */<br>
> + u32 video_nullpkt_size: 13;<br>
> +<br>
> + u32 reserved: 19;<br>
> +<br>
> + } bits;<br>
> + } VIDEO_NULLPKT_SIZE;<br>
> +<br>
> + union _0xC4 {<br>
> + u32 val;<br>
> + struct _DCS_WM_PKT_SIZE {<br>
> + /*<br>
> + * This field configures the maximum allowed size for an eDPI<br>
> + * write memory command, measured in pixels. Automatic parti-<br>
> + * tioning of data obtained from eDPI is permanently enabled.<br>
> + */<br>
> + u32 dcs_wm_pkt_size: 16;<br>
> +<br>
> + u32 reserved: 16;<br>
> + } bits;<br>
> + } DCS_WM_PKT_SIZE;<br>
> +<br>
> + union _0xC8 {<br>
> + u32 val;<br>
> + struct _PROTOCOL_INT_CLR {<br>
> + u32 clr_dphy_errors_0: 1;<br>
> + u32 clr_dphy_errors_1: 1;<br>
> + u32 clr_dphy_errors_2: 1;<br>
> + u32 clr_dphy_errors_3: 1;<br>
> + u32 clr_dphy_errors_4: 1;<br>
> + u32 clr_protocol_debug_err: 11;<br>
> + u32 clr_ack_with_err_0: 1;<br>
> + u32 clr_ack_with_err_1: 1;<br>
> + u32 clr_ack_with_err_2: 1;<br>
> + u32 clr_ack_with_err_3: 1;<br>
> + u32 clr_ack_with_err_4: 1;<br>
> + u32 clr_ack_with_err_5: 1;<br>
> + u32 clr_ack_with_err_6: 1;<br>
> + u32 clr_ack_with_err_7: 1;<br>
> + u32 clr_ack_with_err_8: 1;<br>
> + u32 clr_ack_with_err_9: 1;<br>
> + u32 clr_ack_with_err_10: 1;<br>
> + u32 clr_ack_with_err_11: 1;<br>
> + u32 clr_ack_with_err_12: 1;<br>
> + u32 clr_ack_with_err_13: 1;<br>
> + u32 clr_ack_with_err_14: 1;<br>
> + u32 clr_ack_with_err_15: 1;<br>
> + } bits;<br>
> + } PROTOCOL_INT_CLR;<br>
> +<br>
> + union _0xCC {<br>
> + u32 val;<br>
> + struct _INTERNAL_INT_CLR {<br>
> + u32 clr_receive_pkt_size_err: 1;<br>
> + u32 clr_eopt_not_receive_err: 1;<br>
> + u32 clr_gen_cmd_cmd_fifo_wr_err: 1;<br>
> + u32 clr_gen_cmd_rdata_fifo_rd_err: 1;<br>
> + u32 clr_gen_cmd_rdata_fifo_wr_err: 1;<br>
> + u32 clr_gen_cmd_wdata_fifo_wr_err: 1;<br>
> + u32 clr_gen_cmd_wdata_fifo_rd_err: 1;<br>
> + u32 clr_dpi_pix_fifo_wr_err: 1;<br>
> + u32 clr_internal_debug_err: 19;<br>
> + u32 clr_ecc_single_err: 1;<br>
> + u32 clr_ecc_multi_err: 1;<br>
> + u32 clr_crc_err: 1;<br>
> + u32 clr_hs_tx_timeout: 1;<br>
> + u32 clr_lp_rx_timeout: 1;<br>
> + } bits;<br>
> + } INTERNAL_INT_CLR;<br>
> +<br>
> + union _0xD0 {<br>
> + u32 val;<br>
> + struct _VIDEO_SIG_DELAY_CONFIG {<br>
> +<br>
> + /*<br>
> + * DPI interface signal delay to be used in clk lanebyte<br>
> + * domain for control logic to read video data from pixel<br>
> + * memory in mannal mode, measured in clk_lanebyte cycles<br>
> + */<br>
> + u32 video_sig_delay: 24;<br>
> +<br>
> + /*<br>
> + * 1'b1: mannal mode<br>
> + * dsi controller will use video_sig_delay value as<br>
> + * the delay for the packet handle logic to read video<br>
> + * data from pixel memory.<br>
> + *<br>
> + * 1'b0: auto mode<br>
> + * dsi controller will auto calculate the delay for<br>
> + * the packet handle logic to read video data from<br>
> + * pixel memory.<br>
> + */<br>
> + u32 video_sig_delay_mode: 1;<br>
> +<br>
> + u32 reserved: 7;<br>
> + } bits;<br>
> + } VIDEO_SIG_DELAY_CONFIG;<br>
> +<br>
> + u32 reservedD4_EC[7];<br>
> +<br>
> + union _0xF0 {<br>
> + u32 val;<br>
> + struct _PHY_TST_CTRL0 {<br>
> + /* PHY test interface clear (active high) */<br>
> + u32 phy_testclr: 1;<br>
> +<br>
> + /* This bit is used to clock the TESTDIN bus into the D-PHY */<br>
> + u32 phy_testclk: 1;<br>
> +<br>
> + u32 reserved: 30;<br>
> + } bits;<br>
> + } PHY_TST_CTRL0;<br>
> +<br>
> + union _0xF4 {<br>
> + u32 val;<br>
> + struct _PHY_TST_CTRL1 {<br>
> + /* PHY test interface input 8-bit data bus for internal<br>
> + * register programming and test functionalities access.<br>
> + */<br>
> + u32 phy_testdin: 8;<br>
> +<br>
> + /* PHY output 8-bit data bus for read-back and internal<br>
> + * probing functionalities.<br>
> + */<br>
> + u32 phy_testdout: 8;<br>
> +<br>
> + /*<br>
> + * PHY test interface operation selector:<br>
> + * 1: The address write operation is set on the falling edge<br>
> + * of the testclk signal.<br>
> + * 0: The data write operation is set on the rising edge of<br>
> + * the testclk signal.<br>
> + */<br>
> + u32 phy_testen: 1;<br>
> +<br>
> + u32 reserved: 15;<br>
> + } bits;<br>
> + } PHY_TST_CTRL1;<br>
> +<br>
> + u32 reservedF8_1FC[66];<br>
> +<br>
> + union _0x200 {<br>
> + u32 val;<br>
> + struct _INT_PLL_STS {<br>
> + u32 int_pll_sts: 1;<br>
> + u32 reserved: 31;<br>
> + } bits;<br>
> + } INT_PLL_STS;<br>
> +<br>
> + union _0x204 {<br>
> + u32 val;<br>
> + struct _INT_PLL_MSK {<br>
> + u32 int_pll_msk: 1;<br>
> + u32 reserved: 31;<br>
> + } bits;<br>
> + } INT_PLL_MSK;<br>
> +<br>
> + union _0x208 {<br>
> + u32 val;<br>
> + struct _INT_PLL_CLR {<br>
> + u32 int_pll_clr: 1;<br>
> + u32 reserved: 31;<br>
> + } bits;<br>
> + } INT_PLL_CLR;<br>
> +<br>
> +};<br>
> +<br>
> +void dsi_power_enable(struct dsi_context *ctx, int enable);<br>
> +void dsi_video_mode(struct dsi_context *ctx);<br>
> +void dsi_cmd_mode(struct dsi_context *ctx);<br>
> +bool dsi_is_cmd_mode(struct dsi_context *ctx);<br>
> +void dsi_rx_vcid(struct dsi_context *ctx, u8 vc);<br>
> +void dsi_video_vcid(struct dsi_context *ctx, u8 vc);<br>
> +void dsi_dpi_video_burst_mode(struct dsi_context *ctx, int mode);<br>
> +void dsi_dpi_color_coding(struct dsi_context *ctx, int coding);<br>
> +void dsi_dpi_sig_delay(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_dpi_hline_time(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_dpi_hsync_time(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_dpi_hbp_time(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_dpi_vact(struct dsi_context *ctx, u16 lines);<br>
> +void dsi_dpi_vfp(struct dsi_context *ctx, u16 lines);<br>
> +void dsi_dpi_vbp(struct dsi_context *ctx, u16 lines);<br>
> +void dsi_dpi_vsync(struct dsi_context *ctx, u16 lines);<br>
> +void dsi_dpi_hporch_lp_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_dpi_vporch_lp_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_dpi_frame_ack_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_dpi_chunk_num(struct dsi_context *ctx, u16 no);<br>
> +void dsi_dpi_null_packet_size(struct dsi_context *ctx, u16 size);<br>
> +void dsi_dpi_video_packet_size(struct dsi_context *ctx, u16 size);<br>
> +void dsi_edpi_max_pkt_size(struct dsi_context *ctx, u16 size);<br>
> +void dsi_tear_effect_ack_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_cmd_mode_lp_cmd_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_video_mode_lp_cmd_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_set_packet_header(struct dsi_context *ctx, u8 vc, u8 type,<br>
> + u8 wc_lsb, u8 wc_msb);<br>
> +void dsi_set_packet_payload(struct dsi_context *ctx, u32 payload);<br>
> +u32 dsi_get_rx_payload(struct dsi_context *ctx);<br>
> +void dsi_bta_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_eotp_rx_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_eotp_tx_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_ecc_rx_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_crc_rx_en(struct dsi_context *ctx, int enable);<br>
> +bool dsi_is_bta_returned(struct dsi_context *ctx);<br>
> +bool dsi_is_rx_payload_fifo_full(struct dsi_context *ctx);<br>
> +bool dsi_is_rx_payload_fifo_empty(struct dsi_context *ctx);<br>
> +bool dsi_is_tx_payload_fifo_full(struct dsi_context *ctx);<br>
> +bool dsi_is_tx_payload_fifo_empty(struct dsi_context *ctx);<br>
> +bool dsi_is_tx_cmd_fifo_empty(struct dsi_context *ctx);<br>
> +void dsi_datalane_hs2lp_config(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_datalane_lp2hs_config(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_clklane_hs2lp_config(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_clklane_lp2hs_config(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_max_read_time(struct dsi_context *ctx, u16 byte_cycle);<br>
> +void dsi_nc_clk_en(struct dsi_context *ctx, int enable);<br>
> +void dsi_tx_escape_division(struct dsi_context *ctx, u8 div);<br>
> +void dsi_timeout_clock_division(struct dsi_context *ctx, u8 div);<br>
> +void dsi_lp_rx_timeout(struct dsi_context *ctx, u16 count);<br>
> +void dsi_hs_tx_timeout(struct dsi_context *ctx, u16 count);<br>
> +u32 dsi_int0_status(struct dsi_context *ctx);<br>
> +u32 dsi_int1_status(struct dsi_context *ctx);<br>
> +void dsi_int0_mask(struct dsi_context *ctx, u32 mask);<br>
> +void dsi_int1_mask(struct dsi_context *ctx, u32 mask);<br>
> +<br>
> +#endif /* _DW_DSI_CTRL_H_ */<br>
> diff --git a/drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.c b/drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.c<br>
> new file mode 100644<br>
> index 0000000..6e28d7c<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.c<br>
> @@ -0,0 +1,157 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <linux/io.h><br>
> +#include <linux/init.h><br>
> +#include <linux/module.h><br>
> +<br>
> +#include "dw_dsi_ctrl.h"<br>
> +#include "dw_dsi_ctrl_ppi.h"<br>
> +<br>
> +/*<br>
> + * Reset D-PHY module<br>
> + */<br>
> +void dsi_phy_rstz(struct dsi_context *ctx, int level)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x78 phy_interface_ctrl;<br>
> +<br>
> + phy_interface_ctrl.val = readl(®->PHY_INTERFACE_CTRL);<br>
> + phy_interface_ctrl.bits.rf_phy_reset_n = level;<br>
> +<br>
> + writel(phy_interface_ctrl.val, ®->PHY_INTERFACE_CTRL);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Power up/down D-PHY module<br>
> + */<br>
> +void dsi_phy_shutdownz(struct dsi_context *ctx, int level)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x78 phy_interface_ctrl;<br>
> +<br>
> + phy_interface_ctrl.val = readl(®->PHY_INTERFACE_CTRL);<br>
> + phy_interface_ctrl.bits.rf_phy_shutdown = level;<br>
> +<br>
> + writel(phy_interface_ctrl.val, ®->PHY_INTERFACE_CTRL);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Configure minimum wait period for HS transmission request after a stop state<br>
> + */<br>
> +void dsi_phy_stop_wait_time(struct dsi_context *ctx, u8 byte_cycle)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(byte_cycle, ®->PHY_MIN_STOP_TIME);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Set number of active lanes<br>
> + */<br>
> +void dsi_phy_datalane_en(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> +<br>
> + writel(ctx->lanes - 1, ®->PHY_LANE_NUM_CONFIG);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Enable clock lane module<br>
> + */<br>
> +void dsi_phy_clklane_en(struct dsi_context *ctx, int en)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x78 phy_interface_ctrl;<br>
> +<br>
> + phy_interface_ctrl.val = readl(®->PHY_INTERFACE_CTRL);<br>
> + phy_interface_ctrl.bits.rf_phy_clk_en = en;<br>
> +<br>
> + writel(phy_interface_ctrl.val, ®->PHY_INTERFACE_CTRL);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Request the PHY module to start transmission of high speed clock.<br>
> + * This causes the clock lane to start transmitting DDR clock on the<br>
> + * lane interconnect.<br>
> + */<br>
> +void dsi_phy_clk_hs_rqst(struct dsi_context *ctx, int enable)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x74 phy_clk_lane_lp_ctrl;<br>
> +<br>
> + phy_clk_lane_lp_ctrl.val = readl(®->PHY_CLK_LANE_LP_CTRL);<br>
> + phy_clk_lane_lp_ctrl.bits.auto_clklane_ctrl_en = 0;<br>
> + phy_clk_lane_lp_ctrl.bits.phy_clklane_tx_req_hs = enable;<br>
> +<br>
> + writel(phy_clk_lane_lp_ctrl.val, ®->PHY_CLK_LANE_LP_CTRL);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Get D-PHY PPI status<br>
> + */<br>
> +u8 dsi_phy_is_pll_locked(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0x9C phy_status;<br>
> +<br>
> + phy_status.val = readl(®->PHY_STATUS);<br>
> +<br>
> + return phy_status.bits.phy_lock;<br>
> +}<br>
> +<br>
> +void dsi_phy_test_clk(struct dsi_context *ctx, u8 value)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xF0 phy_tst_ctrl0;<br>
> +<br>
> + phy_tst_ctrl0.val = readl(®->PHY_TST_CTRL0);<br>
> + phy_tst_ctrl0.bits.phy_testclk = value;<br>
> +<br>
> + writel(phy_tst_ctrl0.val, ®->PHY_TST_CTRL0);<br>
> +}<br>
> +<br>
> +void dsi_phy_test_clr(struct dsi_context *ctx, u8 value)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xF0 phy_tst_ctrl0;<br>
> +<br>
> + phy_tst_ctrl0.val = readl(®->PHY_TST_CTRL0);<br>
> + phy_tst_ctrl0.bits.phy_testclr = value;<br>
> +<br>
> + writel(phy_tst_ctrl0.val, ®->PHY_TST_CTRL0);<br>
> +}<br>
> +<br>
> +void dsi_phy_test_en(struct dsi_context *ctx, u8 value)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xF4 phy_tst_ctrl1;<br>
> +<br>
> + phy_tst_ctrl1.val = readl(®->PHY_TST_CTRL1);<br>
> + phy_tst_ctrl1.bits.phy_testen = value;<br>
> +<br>
> + writel(phy_tst_ctrl1.val, ®->PHY_TST_CTRL1);<br>
> +}<br>
> +<br>
> +u8 dsi_phy_test_dout(struct dsi_context *ctx)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xF4 phy_tst_ctrl1;<br>
> +<br>
> + phy_tst_ctrl1.val = readl(®->PHY_TST_CTRL1);<br>
> +<br>
> + return phy_tst_ctrl1.bits.phy_testdout;<br>
> +}<br>
> +<br>
> +void dsi_phy_test_din(struct dsi_context *ctx, u8 data)<br>
> +{<br>
> + struct dsi_reg *reg = (struct dsi_reg *)ctx->base;<br>
> + union _0xF4 phy_tst_ctrl1;<br>
> +<br>
> + phy_tst_ctrl1.val = readl(®->PHY_TST_CTRL1);<br>
> + phy_tst_ctrl1.bits.phy_testdin = data;<br>
> +<br>
> + writel(phy_tst_ctrl1.val, ®->PHY_TST_CTRL1);<br>
> +}<br>
> diff --git a/drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.h b/drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.h<br>
> new file mode 100644<br>
> index 0000000..d87fb75<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/dw_dsi_ctrl_ppi.h<br>
> @@ -0,0 +1,26 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#ifndef _DW_DSI_CTRL_PPI_H_<br>
> +#define _DW_DSI_CTRL_PPI_H_<br>
> +<br>
> +#include "sprd_dsi.h"<br>
> +<br>
> +void dsi_phy_rstz(struct dsi_context *ctx, int level);<br>
> +void dsi_phy_shutdownz(struct dsi_context *ctx, int level);<br>
> +void dsi_phy_force_pll(struct dsi_context *ctx, int force);<br>
> +void dsi_phy_stop_wait_time(struct dsi_context *ctx, u8 byte_clk);<br>
> +void dsi_phy_datalane_en(struct dsi_context *ctx);<br>
> +void dsi_phy_clklane_en(struct dsi_context *ctx, int en);<br>
> +void dsi_phy_clk_hs_rqst(struct dsi_context *ctx, int en);<br>
> +u8 dsi_phy_is_pll_locked(struct dsi_context *ctx);<br>
> +void dsi_phy_test_clk(struct dsi_context *ctx, u8 level);<br>
> +void dsi_phy_test_clr(struct dsi_context *ctx, u8 level);<br>
> +void dsi_phy_test_en(struct dsi_context *ctx, u8 level);<br>
> +u8 dsi_phy_test_dout(struct dsi_context *ctx);<br>
> +void dsi_phy_test_din(struct dsi_context *ctx, u8 data);<br>
> +void dsi_phy_bist_en(struct dsi_context *ctx, int en);<br>
> +<br>
> +#endif /* _DW_DSI_CTRL_PPI_H_ */<br>
> \ No newline at end of file<br>
> diff --git a/drivers/gpu/drm/sprd/megacores_pll.c b/drivers/gpu/drm/sprd/megacores_pll.c<br>
> new file mode 100644<br>
> index 0000000..03c1f0f<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/megacores_pll.c<br>
> @@ -0,0 +1,317 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <asm/div64.h><br>
> +#include <linux/delay.h><br>
> +#include <linux/init.h><br>
> +#include <linux/kernel.h><br>
> +#include <linux/regmap.h><br>
> +#include <linux/string.h><br>
> +<br>
> +#include "megacores_pll.h"<br>
> +<br>
> +#define L 0<br>
> +#define H 1<br>
> +#define CLK 0<br>
> +#define DATA 1<br>
> +#define INFINITY 0xffffffff<br>
> +#define MIN_OUTPUT_FREQ (100)<br>
> +<br>
> +#define AVERAGE(a, b) (min(a, b) + abs((b) - (a)) / 2)<br>
> +<br>
> +/* sharkle */<br>
> +#define VCO_BAND_LOW 750<br>
> +#define VCO_BAND_MID 1100<br>
> +#define VCO_BAND_HIGH 1500<br>
> +#define PHY_REF_CLK 26000<br>
> +<br>
> +static int dphy_calc_pll_param(struct dphy_pll *pll)<br>
> +{<br>
> + const u32 khz = 1000;<br>
> + const u32 mhz = 1000000;<br>
> + const unsigned long long factor = 100;<br>
> + unsigned long long tmp;<br>
> + int i;<br>
> +<br>
> + pll->potential_fvco = pll->freq / khz;<br>
> + pll->ref_clk = PHY_REF_CLK / khz;<br>
> +<br>
> + for (i = 0; i < 4; ++i) {<br>
> + if (pll->potential_fvco >= VCO_BAND_LOW &&<br>
> + pll->potential_fvco <= VCO_BAND_HIGH) {<br>
> + pll->fvco = pll->potential_fvco;<br>
> + pll->out_sel = BIT(i);<br>
> + break;<br>
> + }<br>
> + pll->potential_fvco <<= 1;<br>
> + }<br>
> + if (pll->fvco == 0)<br>
> + return -EINVAL;<br>
> +<br>
> + if (pll->fvco >= VCO_BAND_LOW && pll->fvco <= VCO_BAND_MID) {<br>
> + /* vco band control */<br>
> + pll->vco_band = 0x0;<br>
> + /* low pass filter control */<br>
> + pll->lpf_sel = 1;<br>
> + } else if (pll->fvco > VCO_BAND_MID && pll->fvco <= VCO_BAND_HIGH) {<br>
> + pll->vco_band = 0x1;<br>
> + pll->lpf_sel = 0;<br>
> + } else<br>
> + return -EINVAL;<br>
> +<br>
> + pll->nint = pll->fvco / pll->ref_clk;<br>
> + tmp = pll->fvco * factor * mhz;<br>
> + do_div(tmp, pll->ref_clk);<br>
> + tmp = tmp - pll->nint * factor * mhz;<br>
> + tmp *= BIT(20);<br>
> + do_div(tmp, 100000000);<br>
> + pll->kint = (u32)tmp;<br>
> + pll->refin = 3; /* pre-divider bypass */<br>
> + pll->sdm_en = true; /* use fraction N PLL */<br>
> + pll->fdk_s = 0x1; /* fraction */<br>
> + pll->cp_s = 0x0;<br>
> + pll->det_delay = 0x1;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void dphy_set_pll_reg(struct dphy_pll *pll, struct regmap *regmap)<br>
> +{<br>
> + struct pll_reg *reg = &pll->reg;<br>
> + u8 *val;<br>
> + int i;<br>
> +<br>
> + u8 reg_addr[] = {<br>
> + 0x03, 0x04, 0x06, 0x08, 0x09,<br>
> + 0x0a, 0x0b, 0x0e, 0x0f<br>
> + };<br>
> +<br>
> + reg->_03.bits.prbs_bist = 1;<br>
> + reg->_03.bits.en_lp_treot = true;<br>
> + reg->_03.bits.lpf_sel = pll->lpf_sel;<br>
> + reg->_03.bits.txfifo_bypass = 0;<br>
> + reg->_04.bits.div = pll->div;<br>
> + reg->_04.bits.masterof8lane = 1;<br>
> + reg->_04.bits.cp_s = pll->cp_s;<br>
> + reg->_04.bits.fdk_s = pll->fdk_s;<br>
> + reg->_06.bits.nint = pll->nint;<br>
> + reg->_08.bits.vco_band = pll->vco_band;<br>
> + reg->_08.bits.sdm_en = pll->sdm_en;<br>
> + reg->_08.bits.refin = pll->refin;<br>
> + reg->_09.bits.kint_h = pll->kint >> 12;<br>
> + reg->_0a.bits.kint_m = (pll->kint >> 4) & 0xff;<br>
> + reg->_0b.bits.out_sel = pll->out_sel;<br>
> + reg->_0b.bits.kint_l = pll->kint & 0xf;<br>
> + reg->_0e.bits.pll_pu_byp = 0;<br>
> + reg->_0e.bits.pll_pu = 0;<br>
> + reg->_0e.bits.stopstate_sel = 1;<br>
> + reg->_0f.bits.det_delay = pll->det_delay;<br>
> +<br>
> + val = (u8 *)®<br>
> +<br>
> + for (i = 0; i < sizeof(reg_addr); ++i) {<br>
> + regmap_write(regmap, reg_addr[i], val[i]);<br>
> + DRM_DEBUG("%02x: %02x\n", reg_addr[i], val[i]);<br>
> + }<br>
> +}<br>
> +<br>
> +int dphy_pll_config(struct dsi_context *ctx)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + struct regmap *regmap = ctx->regmap;<br>
> + struct dphy_pll *pll = ctx->pll;<br>
> + int ret;<br>
> +<br>
> + pll->freq = ctx->byte_clk * 8;<br>
> +<br>
> + /* FREQ = 26M * (NINT + KINT / 2^20) / out_sel */<br>
> + ret = dphy_calc_pll_param(pll);<br>
> + if (ret) {<br>
> + drm_err(dsi->drm, "failed to calculate dphy pll parameters\n");<br>
> + return ret;<br>
> + }<br>
> + dphy_set_pll_reg(pll, regmap);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void dphy_set_timing_reg(struct regmap *regmap, int type, u8 val[])<br>
> +{<br>
> + switch (type) {<br>
> + case REQUEST_TIME:<br>
> + regmap_write(regmap, 0x31, val[CLK]);<br>
> + regmap_write(regmap, 0x41, val[DATA]);<br>
> + regmap_write(regmap, 0x51, val[DATA]);<br>
> + regmap_write(regmap, 0x61, val[DATA]);<br>
> + regmap_write(regmap, 0x71, val[DATA]);<br>
> +<br>
> + regmap_write(regmap, 0x90, val[CLK]);<br>
> + regmap_write(regmap, 0xa0, val[DATA]);<br>
> + regmap_write(regmap, 0xb0, val[DATA]);<br>
> + regmap_write(regmap, 0xc0, val[DATA]);<br>
> + regmap_write(regmap, 0xd0, val[DATA]);<br>
> + break;<br>
> + case PREPARE_TIME:<br>
> + regmap_write(regmap, 0x32, val[CLK]);<br>
> + regmap_write(regmap, 0x42, val[DATA]);<br>
> + regmap_write(regmap, 0x52, val[DATA]);<br>
> + regmap_write(regmap, 0x62, val[DATA]);<br>
> + regmap_write(regmap, 0x72, val[DATA]);<br>
> +<br>
> + regmap_write(regmap, 0x91, val[CLK]);<br>
> + regmap_write(regmap, 0xa1, val[DATA]);<br>
> + regmap_write(regmap, 0xb1, val[DATA]);<br>
> + regmap_write(regmap, 0xc1, val[DATA]);<br>
> + regmap_write(regmap, 0xd1, val[DATA]);<br>
> + break;<br>
> + case ZERO_TIME:<br>
> + regmap_write(regmap, 0x33, val[CLK]);<br>
> + regmap_write(regmap, 0x43, val[DATA]);<br>
> + regmap_write(regmap, 0x53, val[DATA]);<br>
> + regmap_write(regmap, 0x63, val[DATA]);<br>
> + regmap_write(regmap, 0x73, val[DATA]);<br>
> +<br>
> + regmap_write(regmap, 0x92, val[CLK]);<br>
> + regmap_write(regmap, 0xa2, val[DATA]);<br>
> + regmap_write(regmap, 0xb2, val[DATA]);<br>
> + regmap_write(regmap, 0xc2, val[DATA]);<br>
> + regmap_write(regmap, 0xd2, val[DATA]);<br>
> + break;<br>
> + case TRAIL_TIME:<br>
> + regmap_write(regmap, 0x34, val[CLK]);<br>
> + regmap_write(regmap, 0x44, val[DATA]);<br>
> + regmap_write(regmap, 0x54, val[DATA]);<br>
> + regmap_write(regmap, 0x64, val[DATA]);<br>
> + regmap_write(regmap, 0x74, val[DATA]);<br>
> +<br>
> + regmap_write(regmap, 0x93, val[CLK]);<br>
> + regmap_write(regmap, 0xa3, val[DATA]);<br>
> + regmap_write(regmap, 0xb3, val[DATA]);<br>
> + regmap_write(regmap, 0xc3, val[DATA]);<br>
> + regmap_write(regmap, 0xd3, val[DATA]);<br>
> + break;<br>
> + case EXIT_TIME:<br>
> + regmap_write(regmap, 0x36, val[CLK]);<br>
> + regmap_write(regmap, 0x46, val[DATA]);<br>
> + regmap_write(regmap, 0x56, val[DATA]);<br>
> + regmap_write(regmap, 0x66, val[DATA]);<br>
> + regmap_write(regmap, 0x76, val[DATA]);<br>
> +<br>
> + regmap_write(regmap, 0x95, val[CLK]);<br>
> + regmap_write(regmap, 0xA5, val[DATA]);<br>
> + regmap_write(regmap, 0xB5, val[DATA]);<br>
> + regmap_write(regmap, 0xc5, val[DATA]);<br>
> + regmap_write(regmap, 0xd5, val[DATA]);<br>
> + break;<br>
> + case CLKPOST_TIME:<br>
> + regmap_write(regmap, 0x35, val[CLK]);<br>
> + regmap_write(regmap, 0x94, val[CLK]);<br>
> + break;<br>
> +<br>
> + /* the following just use default value */<br>
> + case SETTLE_TIME:<br>
> + case TA_GET:<br>
> + case TA_GO:<br>
> + case TA_SURE:<br>
> + break;<br>
> + default:<br>
> + break;<br>
> + }<br>
> +}<br>
> +<br>
> +void dphy_timing_config(struct dsi_context *ctx)<br>
> +{<br>
> + struct regmap *regmap = ctx->regmap;<br>
> + struct dphy_pll *pll = ctx->pll;<br>
> + const u32 factor = 2;<br>
> + const u32 scale = 100;<br>
> + u32 t_ui, t_byteck, t_half_byteck;<br>
> + u32 range[2], constant;<br>
> + u8 val[2];<br>
> + u32 tmp = 0;<br>
> +<br>
> + /* t_ui: 1 ui, byteck: 8 ui, half byteck: 4 ui */<br>
> + t_ui = 1000 * scale / (pll->freq / 1000);<br>
> + t_byteck = t_ui << 3;<br>
> + t_half_byteck = t_ui << 2;<br>
> + constant = t_ui << 1;<br>
> +<br>
> + /* REQUEST_TIME: HS T-LPX: LP-01<br>
> + * For T-LPX, mipi spec defined min value is 50ns,<br>
> + * but maybe it shouldn't be too small, because BTA,<br>
> + * LP-10, LP-00, LP-01, all of this is related to T-LPX.<br>
> + */<br>
> + range[L] = 50 * scale;<br>
> + range[H] = INFINITY;<br>
> + val[CLK] = DIV_ROUND_UP(range[L] * (factor << 1), t_byteck) - 2;<br>
> + val[DATA] = val[CLK];<br>
> + dphy_set_timing_reg(regmap, REQUEST_TIME, val);<br>
> +<br>
> + /* PREPARE_TIME: HS sequence: LP-00 */<br>
> + range[L] = 38 * scale;<br>
> + range[H] = 95 * scale;<br>
> + tmp = AVERAGE(range[L], range[H]);<br>
> + val[CLK] = DIV_ROUND_UP(AVERAGE(range[L], range[H]),<br>
> + t_half_byteck) - 1;<br>
> + range[L] = 40 * scale + 4 * t_ui;<br>
> + range[H] = 85 * scale + 6 * t_ui;<br>
> + tmp |= AVERAGE(range[L], range[H]) << 16;<br>
> + val[DATA] = DIV_ROUND_UP(AVERAGE(range[L], range[H]),<br>
> + t_half_byteck) - 1;<br>
> + dphy_set_timing_reg(regmap, PREPARE_TIME, val);<br>
> +<br>
> + /* ZERO_TIME: HS-ZERO */<br>
> + range[L] = 300 * scale;<br>
> + range[H] = INFINITY;<br>
> + val[CLK] = DIV_ROUND_UP(range[L] * factor + (tmp & 0xffff)<br>
> + - 525 * t_byteck / 100, t_byteck) - 2;<br>
> + range[L] = 145 * scale + 10 * t_ui;<br>
> + val[DATA] = DIV_ROUND_UP(range[L] * factor<br>
> + + ((tmp >> 16) & 0xffff) - 525 * t_byteck / 100,<br>
> + t_byteck) - 2;<br>
> + dphy_set_timing_reg(regmap, ZERO_TIME, val);<br>
> +<br>
> + /* TRAIL_TIME: HS-TRAIL */<br>
> + range[L] = 60 * scale;<br>
> + range[H] = INFINITY;<br>
> + val[CLK] = DIV_ROUND_UP(range[L] * factor - constant, t_half_byteck);<br>
> + range[L] = max(8 * t_ui, 60 * scale + 4 * t_ui);<br>
> + val[DATA] = DIV_ROUND_UP(range[L] * 3 / 2 - constant, t_half_byteck) - 2;<br>
> + dphy_set_timing_reg(regmap, TRAIL_TIME, val);<br>
> +<br>
> + /* EXIT_TIME: */<br>
> + range[L] = 100 * scale;<br>
> + range[H] = INFINITY;<br>
> + val[CLK] = DIV_ROUND_UP(range[L] * factor, t_byteck) - 2;<br>
> + val[DATA] = val[CLK];<br>
> + dphy_set_timing_reg(regmap, EXIT_TIME, val);<br>
> +<br>
> + /* CLKPOST_TIME: */<br>
> + range[L] = 60 * scale + 52 * t_ui;<br>
> + range[H] = INFINITY;<br>
> + val[CLK] = DIV_ROUND_UP(range[L] * factor, t_byteck) - 2;<br>
> + val[DATA] = val[CLK];<br>
> + dphy_set_timing_reg(regmap, CLKPOST_TIME, val);<br>
> +<br>
> + /* SETTLE_TIME:<br>
> + * This time is used for receiver. So for transmitter,<br>
> + * it can be ignored.<br>
> + */<br>
> +<br>
> + /* TA_GO:<br>
> + * transmitter drives bridge state(LP-00) before releasing control,<br>
> + * reg 0x1f default value: 0x04, which is good.<br>
> + */<br>
> +<br>
> + /* TA_SURE:<br>
> + * After LP-10 state and before bridge state(LP-00),<br>
> + * reg 0x20 default value: 0x01, which is good.<br>
> + */<br>
> +<br>
> + /* TA_GET:<br>
> + * receiver drives Bridge state(LP-00) before releasing control<br>
> + * reg 0x21 default value: 0x03, which is good.<br>
> + */<br>
> +}<br>
> diff --git a/drivers/gpu/drm/sprd/megacores_pll.h b/drivers/gpu/drm/sprd/megacores_pll.h<br>
> new file mode 100644<br>
> index 0000000..750dbbc<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/megacores_pll.h<br>
> @@ -0,0 +1,146 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#ifndef _MEGACORES_PLL_H_<br>
> +#define _MEGACORES_PLL_H_<br>
> +<br>
> +#include "sprd_dsi.h"<br>
> +<br>
> +enum PLL_TIMING {<br>
> + NONE,<br>
> + REQUEST_TIME,<br>
> + PREPARE_TIME,<br>
> + SETTLE_TIME,<br>
> + ZERO_TIME,<br>
> + TRAIL_TIME,<br>
> + EXIT_TIME,<br>
> + CLKPOST_TIME,<br>
> + TA_GET,<br>
> + TA_GO,<br>
> + TA_SURE,<br>
> + TA_WAIT,<br>
> +};<br>
> +<br>
> +struct pll_reg {<br>
> + union __reg_03__ {<br>
> + struct __03 {<br>
> + u8 prbs_bist: 1;<br>
> + u8 en_lp_treot: 1;<br>
> + u8 lpf_sel: 4;<br>
> + u8 txfifo_bypass: 1;<br>
> + u8 freq_hopping: 1;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _03;<br>
> + union __reg_04__ {<br>
> + struct __04 {<br>
> + u8 div: 3;<br>
> + u8 masterof8lane: 1;<br>
> + u8 hop_trig: 1;<br>
> + u8 cp_s: 2;<br>
> + u8 fdk_s: 1;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _04;<br>
> + union __reg_06__ {<br>
> + struct __06 {<br>
> + u8 nint: 7;<br>
> + u8 mod_en: 1;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _06;<br>
> + union __reg_07__ {<br>
> + struct __07 {<br>
> + u8 kdelta_h: 8;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _07;<br>
> + union __reg_08__ {<br>
> + struct __08 {<br>
> + u8 vco_band: 1;<br>
> + u8 sdm_en: 1;<br>
> + u8 refin: 2;<br>
> + u8 kdelta_l: 4;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _08;<br>
> + union __reg_09__ {<br>
> + struct __09 {<br>
> + u8 kint_h: 8;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _09;<br>
> + union __reg_0a__ {<br>
> + struct __0a {<br>
> + u8 kint_m: 8;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _0a;<br>
> + union __reg_0b__ {<br>
> + struct __0b {<br>
> + u8 out_sel: 4;<br>
> + u8 kint_l: 4;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _0b;<br>
> + union __reg_0c__ {<br>
> + struct __0c {<br>
> + u8 kstep_h: 8;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _0c;<br>
> + union __reg_0d__ {<br>
> + struct __0d {<br>
> + u8 kstep_m: 8;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _0d;<br>
> + union __reg_0e__ {<br>
> + struct __0e {<br>
> + u8 pll_pu_byp: 1;<br>
> + u8 pll_pu: 1;<br>
> + u8 hsbist_len: 2;<br>
> + u8 stopstate_sel: 1;<br>
> + u8 kstep_l: 3;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _0e;<br>
> + union __reg_0f__ {<br>
> + struct __0f {<br>
> + u8 det_delay:2;<br>
> + u8 kdelta: 4;<br>
> + u8 ldo0p4:2;<br>
> + } bits;<br>
> + u8 val;<br>
> + } _0f;<br>
> +};<br>
> +<br>
> +struct dphy_pll {<br>
> + u8 refin; /* Pre-divider control signal */<br>
> + u8 cp_s; /* 00: SDM_EN=1, 10: SDM_EN=0 */<br>
> + u8 fdk_s; /* PLL mode control: integer or fraction */<br>
> + u8 sdm_en;<br>
> + u8 div;<br>
> + u8 int_n; /* integer N PLL */<br>
> + u32 ref_clk; /* dphy reference clock, unit: MHz */<br>
> + u32 freq; /* panel config, unit: KHz */<br>
> + u32 fvco;<br>
> + u32 potential_fvco;<br>
> + u32 nint; /* sigma delta modulator NINT control */<br>
> + u32 kint; /* sigma delta modulator KINT control */<br>
> + u8 lpf_sel; /* low pass filter control */<br>
> + u8 out_sel; /* post divider control */<br>
> + u8 vco_band; /* vco range */<br>
> + u8 det_delay;<br>
> +<br>
> + struct pll_reg reg;<br>
> +};<br>
> +<br>
> +struct dsi_context;<br>
> +<br>
> +int dphy_pll_config(struct dsi_context *ctx);<br>
> +void dphy_timing_config(struct dsi_context *ctx);<br>
> +<br>
> +#endif /* _MEGACORES_PLL_H_ */<br>
> \ No newline at end of file<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_drm.c b/drivers/gpu/drm/sprd/sprd_drm.c<br>
> index ca93be2..5323e23 100644<br>
> --- a/drivers/gpu/drm/sprd/sprd_drm.c<br>
> +++ b/drivers/gpu/drm/sprd/sprd_drm.c<br>
> @@ -197,6 +197,7 @@ static struct platform_driver sprd_drm_driver = {<br>
> static struct platform_driver *sprd_drm_drivers[] = {<br>
> &sprd_drm_driver,<br>
> &sprd_dpu_driver,<br>
> + &sprd_dsi_driver,<br>
> };<br>
> <br>
> static int __init sprd_drm_init(void)<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_drm.h b/drivers/gpu/drm/sprd/sprd_drm.h<br>
> index 85d4a8b..95d1b97 100644<br>
> --- a/drivers/gpu/drm/sprd/sprd_drm.h<br>
> +++ b/drivers/gpu/drm/sprd/sprd_drm.h<br>
> @@ -14,5 +14,6 @@ struct sprd_drm {<br>
> };<br>
> <br>
> extern struct platform_driver sprd_dpu_driver;<br>
> +extern struct platform_driver sprd_dsi_driver;<br>
> <br>
> #endif /* _SPRD_DRM_H_ */<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c<br>
> new file mode 100644<br>
> index 0000000..4ebc1aa<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_dsi.c<br>
> @@ -0,0 +1,1162 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <linux/component.h><br>
> +#include <linux/module.h><br>
> +#include <linux/of_address.h><br>
> +#include <linux/of_device.h><br>
> +#include <linux/of_irq.h><br>
> +#include <linux/of_graph.h><br>
> +#include <video/mipi_display.h><br>
> +<br>
> +#include <drm/drm_atomic_helper.h><br>
> +#include <drm/drm_crtc_helper.h><br>
> +#include <drm/drm_of.h><br>
> +#include <drm/drm_probe_helper.h><br>
> +<br>
> +#include "sprd_drm.h"<br>
> +#include "sprd_dpu.h"<br>
> +#include "sprd_dsi.h"<br>
> +#include "dw_dsi_ctrl.h"<br>
> +#include "dw_dsi_ctrl_ppi.h"<br>
> +<br>
> +#define encoder_to_dsi(encoder) \<br>
> + container_of(encoder, struct sprd_dsi, encoder)<br>
> +#define host_to_dsi(host) \<br>
> + container_of(host, struct sprd_dsi, host)<br>
> +#define connector_to_dsi(connector) \<br>
> + container_of(connector, struct sprd_dsi, connector)<br>
> +<br>
> +static int regmap_tst_io_write(void *context, u32 reg, u32 val)<br>
> +{<br>
> + struct sprd_dsi *dsi = context;<br>
> + struct dsi_context *ctx = &dsi->ctx;<br>
> +<br>
> + if (val > 0xff || reg > 0xff)<br>
> + return -EINVAL;<br>
> +<br>
> + drm_dbg(dsi->drm, "reg = 0x%02x, val = 0x%02x\n", reg, val);<br>
> +<br>
> + dsi_phy_test_en(ctx, 1);<br>
> + dsi_phy_test_din(ctx, reg);<br>
> + dsi_phy_test_clk(ctx, 1);<br>
> + dsi_phy_test_clk(ctx, 0);<br>
> + dsi_phy_test_en(ctx, 0);<br>
> + dsi_phy_test_din(ctx, val);<br>
> + dsi_phy_test_clk(ctx, 1);<br>
> + dsi_phy_test_clk(ctx, 0);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int regmap_tst_io_read(void *context, u32 reg, u32 *val)<br>
> +{<br>
> + struct sprd_dsi *dsi = context;<br>
> + struct dsi_context *ctx = &dsi->ctx;<br>
> + int ret;<br>
> +<br>
> + if (reg > 0xff)<br>
> + return -EINVAL;<br>
> +<br>
> + dsi_phy_test_en(ctx, 1);<br>
> + dsi_phy_test_din(ctx, reg);<br>
> + dsi_phy_test_clk(ctx, 1);<br>
> + dsi_phy_test_clk(ctx, 0);<br>
> + dsi_phy_test_en(ctx, 0);<br>
> +<br>
> + udelay(1);<br>
> +<br>
> + ret = dsi_phy_test_dout(ctx);<br>
> + if (ret < 0)<br>
> + return ret;<br>
> +<br>
> + *val = ret;<br>
> +<br>
> + drm_dbg(dsi->drm, "reg = 0x%02x, val = 0x%02x\n", reg, *val);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static struct regmap_bus regmap_tst_io = {<br>
> + .reg_write = regmap_tst_io_write,<br>
> + .reg_read = regmap_tst_io_read,<br>
> +};<br>
> +<br>
> +static const struct regmap_config byte_config = {<br>
> + .reg_bits = 8,<br>
> + .val_bits = 8,<br>
> +};<br>
> +<br>
> +static int dphy_wait_pll_locked(struct dsi_context *ctx)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + int i;<br>
> +<br>
> + for (i = 0; i < 50000; i++) {<br>
> + if (dsi_phy_is_pll_locked(ctx))<br>
> + return 0;<br>
> + udelay(3);<br>
> + }<br>
> +<br>
> + drm_err(dsi->drm, "dphy pll can not be locked\n");<br>
> + return -ETIMEDOUT;<br>
> +}<br>
> +<br>
> +static int dsi_wait_tx_payload_fifo_empty(struct dsi_context *ctx)<br>
> +{<br>
> + int i;<br>
> +<br>
> + for (i = 0; i < 5000; i++) {<br>
> + if (dsi_is_tx_payload_fifo_empty(ctx))<br>
> + return 0;<br>
> + udelay(1);<br>
> + }<br>
> +<br>
> + return -ETIMEDOUT;<br>
> +}<br>
> +<br>
> +static int dsi_wait_tx_cmd_fifo_empty(struct dsi_context *ctx)<br>
> +{<br>
> + int i;<br>
> +<br>
> + for (i = 0; i < 5000; i++) {<br>
> + if (dsi_is_tx_cmd_fifo_empty(ctx))<br>
> + return 0;<br>
> + udelay(1);<br>
> + }<br>
> +<br>
> + return -ETIMEDOUT;<br>
> +}<br>
> +<br>
> +static int dsi_wait_rd_resp_completed(struct dsi_context *ctx)<br>
> +{<br>
> + int i;<br>
> +<br>
> + for (i = 0; i < 10000; i++) {<br>
> + if (dsi_is_bta_returned(ctx))<br>
> + return 0;<br>
> + udelay(10);<br>
> + }<br>
> +<br>
> + return -ETIMEDOUT;<br>
> +}<br>
> +<br>
> +static u16 calc_bytes_per_pixel_x100(int coding)<br>
> +{<br>
> + u16 Bpp_x100;<br>
> +<br>
> + switch (coding) {<br>
> + case COLOR_CODE_16BIT_CONFIG1:<br>
> + case COLOR_CODE_16BIT_CONFIG2:<br>
> + case COLOR_CODE_16BIT_CONFIG3:<br>
> + Bpp_x100 = 200;<br>
> + break;<br>
> + case COLOR_CODE_18BIT_CONFIG1:<br>
> + case COLOR_CODE_18BIT_CONFIG2:<br>
> + Bpp_x100 = 225;<br>
> + break;<br>
> + case COLOR_CODE_24BIT:<br>
> + Bpp_x100 = 300;<br>
> + break;<br>
> + case COLOR_CODE_COMPRESSTION:<br>
> + Bpp_x100 = 100;<br>
> + break;<br>
> + case COLOR_CODE_20BIT_YCC422_LOOSELY:<br>
> + Bpp_x100 = 250;<br>
> + break;<br>
> + case COLOR_CODE_24BIT_YCC422:<br>
> + Bpp_x100 = 300;<br>
> + break;<br>
> + case COLOR_CODE_16BIT_YCC422:<br>
> + Bpp_x100 = 200;<br>
> + break;<br>
> + case COLOR_CODE_30BIT:<br>
> + Bpp_x100 = 375;<br>
> + break;<br>
> + case COLOR_CODE_36BIT:<br>
> + Bpp_x100 = 450;<br>
> + break;<br>
> + case COLOR_CODE_12BIT_YCC420:<br>
> + Bpp_x100 = 150;<br>
> + break;<br>
> + default:<br>
> + DRM_ERROR("invalid color coding");<br>
> + Bpp_x100 = 0;<br>
> + break;<br>
> + }<br>
> +<br>
> + return Bpp_x100;<br>
> +}<br>
> +<br>
> +static u8 calc_video_size_step(int coding)<br>
> +{<br>
> + u8 video_size_step;<br>
> +<br>
> + switch (coding) {<br>
> + case COLOR_CODE_16BIT_CONFIG1:<br>
> + case COLOR_CODE_16BIT_CONFIG2:<br>
> + case COLOR_CODE_16BIT_CONFIG3:<br>
> + case COLOR_CODE_18BIT_CONFIG1:<br>
> + case COLOR_CODE_18BIT_CONFIG2:<br>
> + case COLOR_CODE_24BIT:<br>
> + case COLOR_CODE_COMPRESSTION:<br>
> + return video_size_step = 1;<br>
> + case COLOR_CODE_20BIT_YCC422_LOOSELY:<br>
> + case COLOR_CODE_24BIT_YCC422:<br>
> + case COLOR_CODE_16BIT_YCC422:<br>
> + case COLOR_CODE_30BIT:<br>
> + case COLOR_CODE_36BIT:<br>
> + case COLOR_CODE_12BIT_YCC420:<br>
> + return video_size_step = 2;<br>
> + default:<br>
> + DRM_ERROR("invalid color coding");<br>
> + return 0;<br>
> + }<br>
> +}<br>
> +<br>
> +static u16 round_video_size(int coding, u16 video_size)<br>
> +{<br>
> + switch (coding) {<br>
> + case COLOR_CODE_16BIT_YCC422:<br>
> + case COLOR_CODE_24BIT_YCC422:<br>
> + case COLOR_CODE_20BIT_YCC422_LOOSELY:<br>
> + case COLOR_CODE_12BIT_YCC420:<br>
> + /* round up active H pixels to a multiple of 2 */<br>
> + if ((video_size % 2) != 0)<br>
> + video_size += 1;<br>
> + break;<br>
> + default:<br>
> + break;<br>
> + }<br>
> +<br>
> + return video_size;<br>
> +}<br>
> +<br>
> +#define SPRD_MIPI_DSI_FMT_DSC 0xff<br>
> +static u32 fmt_to_coding(u32 fmt)<br>
> +{<br>
> + switch (fmt) {<br>
> + case MIPI_DSI_FMT_RGB565:<br>
> + return COLOR_CODE_16BIT_CONFIG1;<br>
> + case MIPI_DSI_FMT_RGB666:<br>
> + case MIPI_DSI_FMT_RGB666_PACKED:<br>
> + return COLOR_CODE_18BIT_CONFIG1;<br>
> + case MIPI_DSI_FMT_RGB888:<br>
> + return COLOR_CODE_24BIT;<br>
> + case SPRD_MIPI_DSI_FMT_DSC:<br>
> + return COLOR_CODE_COMPRESSTION;<br>
> + default:<br>
> + DRM_ERROR("Unsupported format (%d)\n", fmt);<br>
> + return COLOR_CODE_24BIT;<br>
> + }<br>
> +}<br>
> +<br>
> +#define ns_to_cycle(ns, byte_clk) \<br>
> + DIV_ROUND_UP((ns) * (byte_clk), 1000000)<br>
> +<br>
> +static void sprd_dsi_init(struct dsi_context *ctx)<br>
> +{<br>
> + u16 data_hs2lp, data_lp2hs, clk_hs2lp, clk_lp2hs;<br>
> + u16 max_rd_time;<br>
> + int div;<br>
> +<br>
> + dsi_power_enable(ctx, 0);<br>
> + dsi_int0_mask(ctx, 0xffffffff);<br>
> + dsi_int1_mask(ctx, 0xffffffff);<br>
> + dsi_cmd_mode(ctx);<br>
> + dsi_eotp_rx_en(ctx, 0);<br>
> + dsi_eotp_tx_en(ctx, 0);<br>
> + dsi_ecc_rx_en(ctx, 1);<br>
> + dsi_crc_rx_en(ctx, 1);<br>
> + dsi_bta_en(ctx, 1);<br>
> + dsi_video_vcid(ctx, 0);<br>
> + dsi_rx_vcid(ctx, 0);<br>
> +<br>
> + div = DIV_ROUND_UP(ctx->byte_clk, ctx->esc_clk);<br>
> + dsi_tx_escape_division(ctx, div);<br>
> +<br>
> + max_rd_time = ns_to_cycle(ctx->max_rd_time, ctx->byte_clk);<br>
> + dsi_max_read_time(ctx, max_rd_time);<br>
> +<br>
> + data_hs2lp = ns_to_cycle(ctx->data_hs2lp, ctx->byte_clk);<br>
> + data_lp2hs = ns_to_cycle(ctx->data_lp2hs, ctx->byte_clk);<br>
> + clk_hs2lp = ns_to_cycle(ctx->clk_hs2lp, ctx->byte_clk);<br>
> + clk_lp2hs = ns_to_cycle(ctx->clk_lp2hs, ctx->byte_clk);<br>
> + dsi_datalane_hs2lp_config(ctx, data_hs2lp);<br>
> + dsi_datalane_lp2hs_config(ctx, data_lp2hs);<br>
> + dsi_clklane_hs2lp_config(ctx, clk_hs2lp);<br>
> + dsi_clklane_lp2hs_config(ctx, clk_lp2hs);<br>
> +<br>
> + dsi_power_enable(ctx, 1);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Free up resources and shutdown host controller and PHY<br>
> + */<br>
> +static void sprd_dsi_fini(struct dsi_context *ctx)<br>
> +{<br>
> + dsi_int0_mask(ctx, 0xffffffff);<br>
> + dsi_int1_mask(ctx, 0xffffffff);<br>
> + dsi_power_enable(ctx, 0);<br>
> +}<br>
> +<br>
> +/*<br>
> + * If not in burst mode, it will compute the video and null packet sizes<br>
> + * according to necessity.<br>
> + * Configure timers for data lanes and/or clock lane to return to LP when<br>
> + * bandwidth is not filled by data.<br>
> + */<br>
> +static int sprd_dsi_dpi_video(struct dsi_context *ctx)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + struct videomode *vm = &ctx->vm;<br>
> + u16 Bpp_x100;<br>
> + u16 video_size;<br>
> + u32 ratio_x1000;<br>
> + u16 null_pkt_size = 0;<br>
> + u8 video_size_step;<br>
> + u32 hs_to;<br>
> + u32 total_bytes;<br>
> + u32 bytes_per_chunk;<br>
> + u32 chunks = 0;<br>
> + u32 bytes_left = 0;<br>
> + u32 chunk_overhead;<br>
> + const u8 pkt_header = 6;<br>
> + u8 coding;<br>
> + int div;<br>
> + u16 hline;<br>
> +<br>
> + coding = fmt_to_coding(ctx->format);<br>
> + video_size = round_video_size(coding, vm->hactive);<br>
> + Bpp_x100 = calc_bytes_per_pixel_x100(coding);<br>
> + video_size_step = calc_video_size_step(coding);<br>
> + ratio_x1000 = ctx->byte_clk * 1000 / (vm->pixelclock / 1000);<br>
> + hline = vm->hactive + vm->hsync_len + vm->hfront_porch +<br>
> + vm->hback_porch;<br>
> +<br>
> + dsi_power_enable(ctx, 0);<br>
> + dsi_dpi_frame_ack_en(ctx, ctx->frame_ack_en);<br>
> + dsi_dpi_color_coding(ctx, coding);<br>
> + dsi_dpi_video_burst_mode(ctx, ctx->burst_mode);<br>
> + dsi_dpi_sig_delay(ctx, 95 * hline * ratio_x1000 / 100000);<br>
> + dsi_dpi_hline_time(ctx, hline * ratio_x1000 / 1000);<br>
> + dsi_dpi_hsync_time(ctx, vm->hsync_len * ratio_x1000 / 1000);<br>
> + dsi_dpi_hbp_time(ctx, vm->hback_porch * ratio_x1000 / 1000);<br>
> + dsi_dpi_vact(ctx, vm->vactive);<br>
> + dsi_dpi_vfp(ctx, vm->vfront_porch);<br>
> + dsi_dpi_vbp(ctx, vm->vback_porch);<br>
> + dsi_dpi_vsync(ctx, vm->vsync_len);<br>
> + dsi_dpi_hporch_lp_en(ctx, 1);<br>
> + dsi_dpi_vporch_lp_en(ctx, 1);<br>
> +<br>
> + hs_to = (hline * vm->vactive) + (2 * Bpp_x100) / 100;<br>
> + for (div = 0x80; (div < hs_to) && (div > 2); div--) {<br>
> + if ((hs_to % div) == 0) {<br>
> + dsi_timeout_clock_division(ctx, div);<br>
> + dsi_lp_rx_timeout(ctx, hs_to / div);<br>
> + dsi_hs_tx_timeout(ctx, hs_to / div);<br>
> + break;<br>
> + }<br>
> + }<br>
> +<br>
> + if (ctx->burst_mode == VIDEO_BURST_WITH_SYNC_PULSES) {<br>
> + dsi_dpi_video_packet_size(ctx, video_size);<br>
> + dsi_dpi_null_packet_size(ctx, 0);<br>
> + dsi_dpi_chunk_num(ctx, 0);<br>
> + } else {<br>
> + /* non burst transmission */<br>
> + null_pkt_size = 0;<br>
> +<br>
> + /* bytes to be sent - first as one chunk */<br>
> + bytes_per_chunk = vm->hactive * Bpp_x100 / 100 + pkt_header;<br>
> +<br>
> + /* hline total bytes from the DPI interface */<br>
> + total_bytes = (vm->hactive + vm->hfront_porch) *<br>
> + ratio_x1000 / ctx->lanes / 1000;<br>
> +<br>
> + /* check if the pixels actually fit on the DSI link */<br>
> + if (total_bytes < bytes_per_chunk) {<br>
> + drm_err(dsi->drm, "current resolution can not be set\n");<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + chunk_overhead = total_bytes - bytes_per_chunk;<br>
> +<br>
> + /* overhead higher than 1 -> enable multi packets */<br>
> + if (chunk_overhead > 1) {<br>
> +<br>
> + /* multi packets */<br>
> + for (video_size = video_size_step;<br>
> + video_size < vm->hactive;<br>
> + video_size += video_size_step) {<br>
> +<br>
> + if (vm->hactive * 1000 / video_size % 1000)<br>
> + continue;<br>
> +<br>
> + chunks = vm->hactive / video_size;<br>
> + bytes_per_chunk = Bpp_x100 * video_size / 100<br>
> + + pkt_header;<br>
> + if (total_bytes >= (bytes_per_chunk * chunks)) {<br>
> + bytes_left = total_bytes -<br>
> + bytes_per_chunk * chunks;<br>
> + break;<br>
> + }<br>
> + }<br>
> +<br>
> + /* prevent overflow (unsigned - unsigned) */<br>
> + if (bytes_left > (pkt_header * chunks)) {<br>
> + null_pkt_size = (bytes_left -<br>
> + pkt_header * chunks) / chunks;<br>
> + /* avoid register overflow */<br>
> + if (null_pkt_size > 1023)<br>
> + null_pkt_size = 1023;<br>
> + }<br>
> +<br>
> + } else {<br>
> +<br>
> + /* single packet */<br>
> + chunks = 1;<br>
> +<br>
> + /* must be a multiple of 4 except 18 loosely */<br>
> + for (video_size = vm->hactive;<br>
> + (video_size % video_size_step) != 0;<br>
> + video_size++)<br>
> + ;<br>
> + }<br>
> +<br>
> + dsi_dpi_video_packet_size(ctx, video_size);<br>
> + dsi_dpi_null_packet_size(ctx, null_pkt_size);<br>
> + dsi_dpi_chunk_num(ctx, chunks);<br>
> + }<br>
> +<br>
> + dsi_int0_mask(ctx, ctx->int0_mask);<br>
> + dsi_int1_mask(ctx, ctx->int1_mask);<br>
> + dsi_power_enable(ctx, 1);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_dsi_edpi_video(struct dsi_context *ctx)<br>
> +{<br>
> + const u32 fifo_depth = 1096;<br>
> + const u32 word_length = 4;<br>
> + u32 hactive = ctx->vm.hactive;<br>
> + u32 Bpp_x100;<br>
> + u32 max_fifo_len;<br>
> + u8 coding;<br>
> +<br>
> + coding = fmt_to_coding(ctx->format);<br>
> + Bpp_x100 = calc_bytes_per_pixel_x100(coding);<br>
> + max_fifo_len = word_length * fifo_depth * 100 / Bpp_x100;<br>
> +<br>
> + dsi_power_enable(ctx, 0);<br>
> + dsi_dpi_color_coding(ctx, coding);<br>
> + dsi_tear_effect_ack_en(ctx, ctx->te_ack_en);<br>
> +<br>
> + if (max_fifo_len > hactive)<br>
> + dsi_edpi_max_pkt_size(ctx, hactive);<br>
> + else<br>
> + dsi_edpi_max_pkt_size(ctx, max_fifo_len);<br>
> +<br>
> + dsi_int0_mask(ctx, ctx->int0_mask);<br>
> + dsi_int1_mask(ctx, ctx->int1_mask);<br>
> + dsi_power_enable(ctx, 1);<br>
> +}<br>
> +<br>
> +/*<br>
> + * Send a packet on the generic interface,<br>
> + * this function has an active delay to wait for the buffer to clear.<br>
> + * The delay is limited to:<br>
> + * (param_length / 4) x DSIH_FIFO_ACTIVE_WAIT x register access time<br>
> + * the controller restricts the sending of.<br>
> + * <br>
> + * This function will not be able to send Null and Blanking packets due to<br>
> + * controller restriction<br>
> + */<br>
> +static int sprd_dsi_wr_pkt(struct dsi_context *ctx, u8 vc, u8 type,<br>
> + const u8 *param, u16 len)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + u8 wc_lsbyte, wc_msbyte;<br>
> + u32 payload;<br>
> + int i, j, ret;<br>
> +<br>
> + if (vc > 3)<br>
> + return -EINVAL;<br>
> +<br>
> +<br>
> + /* 1st: for long packet, must config payload first */<br>
> + ret = dsi_wait_tx_payload_fifo_empty(ctx);<br>
> + if (ret) {<br>
> + drm_err(dsi->drm, "tx payload fifo is not empty\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + if (len > 2) {<br>
> + for (i = 0, j = 0; i < len; i += j) {<br>
> + payload = 0;<br>
> + for (j = 0; (j < 4) && ((j + i) < (len)); j++)<br>
> + payload |= param[i + j] << (j * 8);<br>
> +<br>
> + dsi_set_packet_payload(ctx, payload);<br>
> + }<br>
> + wc_lsbyte = len & 0xff;<br>
> + wc_msbyte = len >> 8;<br>
> + } else {<br>
> + wc_lsbyte = (len > 0) ? param[0] : 0;<br>
> + wc_msbyte = (len > 1) ? param[1] : 0;<br>
> + }<br>
> +<br>
> + /* 2nd: then set packet header */<br>
> + ret = dsi_wait_tx_cmd_fifo_empty(ctx);<br>
> + if (ret) {<br>
> + drm_err(dsi->drm, "tx cmd fifo is not empty\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + dsi_set_packet_header(ctx, vc, type, wc_lsbyte, wc_msbyte);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +/*<br>
> + * Send READ packet to peripheral using the generic interface,<br>
> + * this will force command mode and stop video mode (because of BTA).<br>
> + * <br>
> + * This function has an active delay to wait for the buffer to clear,<br>
> + * the delay is limited to 2 x DSIH_FIFO_ACTIVE_WAIT<br>
> + * (waiting for command buffer, and waiting for receiving)<br>
> + * @note this function will enable BTA<br>
> + */<br>
> +static int sprd_dsi_rd_pkt(struct dsi_context *ctx, u8 vc, u8 type,<br>
> + u8 msb_byte, u8 lsb_byte,<br>
> + u8 *buffer, u8 bytes_to_read)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + int i, ret;<br>
> + int count = 0;<br>
> + u32 temp;<br>
> +<br>
> + if (vc > 3)<br>
> + return -EINVAL;<br>
> +<br>
> + /* 1st: send read command to peripheral */<br>
> + if (!dsi_is_tx_cmd_fifo_empty(ctx))<br>
> + return -EIO;<br>
> +<br>
> + dsi_set_packet_header(ctx, vc, type, lsb_byte, msb_byte);<br>
> +<br>
> + /* 2nd: wait peripheral response completed */<br>
> + ret = dsi_wait_rd_resp_completed(ctx);<br>
> + if (ret) {<br>
> + drm_err(dsi->drm, "wait read response time out\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + /* 3rd: get data from rx payload fifo */<br>
> + if (dsi_is_rx_payload_fifo_empty(ctx)) {<br>
> + drm_err(dsi->drm, "rx payload fifo empty\n");<br>
> + return -EIO;<br>
> + }<br>
> +<br>
> + for (i = 0; i < 100; i++) {<br>
> + temp = dsi_get_rx_payload(ctx);<br>
> +<br>
> + if (count < bytes_to_read)<br>
> + buffer[count++] = temp & 0xff;<br>
> + if (count < bytes_to_read)<br>
> + buffer[count++] = (temp >> 8) & 0xff;<br>
> + if (count < bytes_to_read)<br>
> + buffer[count++] = (temp >> 16) & 0xff;<br>
> + if (count < bytes_to_read)<br>
> + buffer[count++] = (temp >> 24) & 0xff;<br>
> +<br>
> + if (dsi_is_rx_payload_fifo_empty(ctx))<br>
> + return count;<br>
> + else {<br>
> + drm_err(dsi->drm, "read too many buffers\n");<br>
> + return -EIO;<br>
> + }<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_dsi_set_work_mode(struct dsi_context *ctx, u8 mode)<br>
> +{<br>
> + if (mode == DSI_MODE_CMD)<br>
> + dsi_cmd_mode(ctx);<br>
> + else<br>
> + dsi_video_mode(ctx);<br>
> +}<br>
> +<br>
> +static void sprd_dsi_lp_cmd_enable(struct dsi_context *ctx, bool enable)<br>
> +{<br>
> + if (dsi_is_cmd_mode(ctx))<br>
> + dsi_cmd_mode_lp_cmd_en(ctx, enable);<br>
> + else<br>
> + dsi_video_mode_lp_cmd_en(ctx, enable);<br>
> +}<br>
> +<br>
> +static void sprd_dsi_state_reset(struct dsi_context *ctx)<br>
> +{<br>
> + dsi_power_enable(ctx, 0);<br>
> + udelay(100);<br>
> + dsi_power_enable(ctx, 1);<br>
> +}<br>
> +<br>
> +static u32 sprd_dsi_int_status(struct dsi_context *ctx, int index)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + u32 status;<br>
> +<br>
> + if (0 == index)<br>
> + status = dsi_int0_status(ctx);<br>
> + else if (1 == index)<br>
> + status = dsi_int1_status(ctx);<br>
> + else {<br>
> + drm_err(dsi->drm, "invalid dsi IRQ index %d\n", index);<br>
> + status = -EINVAL;<br>
> + }<br>
> +<br>
> + return status;<br>
> +}<br>
> +<br>
> +static int sprd_dphy_init(struct dsi_context *ctx)<br>
> +{<br>
> + struct sprd_dsi *dsi = container_of(ctx, struct sprd_dsi, ctx);<br>
> + int ret;<br>
> +<br>
> + dsi_phy_rstz(ctx, 0);<br>
> + dsi_phy_shutdownz(ctx, 0);<br>
> + dsi_phy_clklane_en(ctx, 0);<br>
> +<br>
> + dsi_phy_test_clr(ctx, 0);<br>
> + dsi_phy_test_clr(ctx, 1);<br>
> + dsi_phy_test_clr(ctx, 0);<br>
> +<br>
> + dphy_pll_config(ctx);<br>
> + dphy_timing_config(ctx);<br>
> +<br>
> + dsi_phy_shutdownz(ctx, 1);<br>
> + dsi_phy_rstz(ctx, 1);<br>
> + dsi_phy_stop_wait_time(ctx, 0x1C);<br>
> + dsi_phy_clklane_en(ctx, 1);<br>
> + dsi_phy_datalane_en(ctx);<br>
> +<br>
> + ret = dphy_wait_pll_locked(ctx);<br>
> + if (ret) {<br>
> + drm_err(dsi->drm, "dphy initial failed\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_dphy_fini(struct dsi_context *ctx)<br>
> +{<br>
> + dsi_phy_rstz(ctx, 0);<br>
> + dsi_phy_shutdownz(ctx, 0);<br>
> + dsi_phy_rstz(ctx, 1);<br>
> +}<br>
> +<br>
> +static void sprd_dsi_encoder_enable(struct drm_encoder *encoder)<br>
> +{<br>
> + struct sprd_dsi *dsi = encoder_to_dsi(encoder);<br>
> + struct sprd_dpu *dpu = to_sprd_crtc(encoder->crtc);<br>
> + struct dsi_context *ctx = &dsi->ctx;<br>
> +<br>
> + if (ctx->enabled) {<br>
> + drm_warn(dsi->drm, "dsi is initialized\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + sprd_dsi_init(ctx);<br>
> + if (ctx->work_mode == DSI_MODE_VIDEO)<br>
> + sprd_dsi_dpi_video(ctx);<br>
> + else<br>
> + sprd_dsi_edpi_video(ctx);<br>
> +<br>
> + sprd_dphy_init(ctx);<br>
> +<br>
> + sprd_dsi_lp_cmd_enable(ctx, true);<br>
> +<br>
> + if (dsi->panel) {<br>
> + drm_panel_prepare(dsi->panel);<br>
> + drm_panel_enable(dsi->panel);<br>
> + }<br>
> +<br>
> + sprd_dsi_set_work_mode(ctx, ctx->work_mode);<br>
> + sprd_dsi_state_reset(ctx);<br>
> +<br>
> + if (ctx->nc_clk_en)<br>
> + dsi_nc_clk_en(ctx, true);<br>
> + else {<br>
> + dsi_phy_clk_hs_rqst(ctx, true);<br>
> + dphy_wait_pll_locked(ctx);<br>
> + }<br>
> +<br>
> + sprd_dpu_run(dpu);<br>
> +<br>
> + ctx->enabled = true;<br>
> +}<br>
> +<br>
> +static void sprd_dsi_encoder_disable(struct drm_encoder *encoder)<br>
> +{<br>
> + struct sprd_dsi *dsi = encoder_to_dsi(encoder);<br>
> + struct sprd_dpu *dpu = to_sprd_crtc(encoder->crtc);<br>
> + struct dsi_context *ctx = &dsi->ctx;<br>
> +<br>
> + if (!ctx->enabled) {<br>
> + drm_warn(dsi->drm, "dsi isn't initialized\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + sprd_dpu_stop(dpu);<br>
> + sprd_dsi_set_work_mode(ctx, DSI_MODE_CMD);<br>
> + sprd_dsi_lp_cmd_enable(ctx, true);<br>
> +<br>
> + if (dsi->panel) {<br>
> + drm_panel_disable(dsi->panel);<br>
> + drm_panel_unprepare(dsi->panel);<br>
> + }<br>
> +<br>
> + sprd_dphy_fini(ctx);<br>
> + sprd_dsi_fini(ctx);<br>
> +<br>
> + ctx->enabled = false;<br>
> +}<br>
> +<br>
> +static void sprd_dsi_encoder_mode_set(struct drm_encoder *encoder,<br>
> + struct drm_display_mode *mode,<br>
> + struct drm_display_mode *adj_mode)<br>
> +{<br>
> + struct sprd_dsi *dsi = encoder_to_dsi(encoder);<br>
> +<br>
> + drm_dbg(dsi->drm, "%s() set mode: %s\n", __func__, dsi->mode->name);<br>
> +}<br>
> +<br>
> +static int sprd_dsi_encoder_atomic_check(struct drm_encoder *encoder,<br>
> + struct drm_crtc_state *crtc_state,<br>
> + struct drm_connector_state *conn_state)<br>
> +{<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct drm_encoder_helper_funcs sprd_encoder_helper_funcs = {<br>
> + .atomic_check = sprd_dsi_encoder_atomic_check,<br>
> + .mode_set = sprd_dsi_encoder_mode_set,<br>
> + .enable = sprd_dsi_encoder_enable,<br>
> + .disable = sprd_dsi_encoder_disable<br>
> +};<br>
> +<br>
> +static const struct drm_encoder_funcs sprd_encoder_funcs = {<br>
> + .destroy = drm_encoder_cleanup,<br>
> +};<br>
> +<br>
> +static int sprd_dsi_encoder_init(struct drm_device *drm,<br>
> + struct sprd_dsi *dsi)<br>
> +{<br>
> + struct drm_encoder *encoder = &dsi->encoder;<br>
> + struct device *dev = dsi-><a href="http://host.dev" rel="noreferrer" target="_blank">host.dev</a>;<br>
> + u32 crtc_mask;<br>
> + int ret;<br>
> +<br>
> + crtc_mask = drm_of_find_possible_crtcs(drm, dev->of_node);<br>
> + if (!crtc_mask) {<br>
> + drm_err(drm, "failed to find crtc mask\n");<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + drm_dbg(dsi->drm, "find possible crtcs: 0x%08x\n", crtc_mask);<br>
> +<br>
> + encoder->possible_crtcs = crtc_mask;<br>
> + ret = drm_encoder_init(drm, encoder, &sprd_encoder_funcs,<br>
> + DRM_MODE_ENCODER_DSI, NULL);<br>
> + if (ret) {<br>
> + drm_err(drm, "failed to init dsi encoder\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + drm_encoder_helper_add(encoder, &sprd_encoder_helper_funcs);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_dsi_find_panel(struct sprd_dsi *dsi)<br>
> +{<br>
> + struct device *dev = dsi-><a href="http://host.dev" rel="noreferrer" target="_blank">host.dev</a>;<br>
> + struct device_node *child, *lcds_node;<br>
> + struct drm_panel *panel;<br>
> +<br>
> + /* search /lcds child node first */<br>
> + lcds_node = of_find_node_by_path("/lcds");<br>
> + for_each_child_of_node(lcds_node, child) {<br>
> + panel = of_drm_find_panel(child);<br>
> + if (!IS_ERR(panel)) {<br>
> + dsi->panel = panel;<br>
> + return 0;<br>
> + }<br>
> + }<br>
> +<br>
> + /*<br>
> + * If /lcds child node search failed, we search<br>
> + * the child of dsi host node.<br>
> + */<br>
> + for_each_child_of_node(dev->of_node, child) {<br>
> + panel = of_drm_find_panel(child);<br>
> + if (!IS_ERR(panel)) {<br>
> + dsi->panel = panel;<br>
> + return 0;<br>
> + }<br>
> + }<br>
> +<br>
> + drm_err(dsi->drm, "of_drm_find_panel() failed\n");<br>
> + return -ENODEV;<br>
> +}<br>
> +<br>
> +static int sprd_dsi_host_attach(struct mipi_dsi_host *host,<br>
> + struct mipi_dsi_device *slave)<br>
> +{<br>
> + struct sprd_dsi *dsi = host_to_dsi(host);<br>
> + struct dsi_context *ctx = &dsi->ctx;<br>
> + int ret;<br>
> +<br>
> + dsi->slave = slave;<br>
> + ctx->lanes = slave->lanes;<br>
> + ctx->format = slave->format;<br>
> + ctx->byte_clk = slave->hs_rate / 8;<br>
> + ctx->esc_clk = slave->lp_rate;<br>
> +<br>
> + if (slave->mode_flags & MIPI_DSI_MODE_VIDEO)<br>
> + ctx->work_mode = DSI_MODE_VIDEO;<br>
> + else<br>
> + ctx->work_mode = DSI_MODE_CMD;<br>
> +<br>
> + if (slave->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)<br>
> + ctx->burst_mode = VIDEO_BURST_WITH_SYNC_PULSES;<br>
> + else if (slave->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)<br>
> + ctx->burst_mode = VIDEO_NON_BURST_WITH_SYNC_PULSES;<br>
> + else<br>
> + ctx->burst_mode = VIDEO_NON_BURST_WITH_SYNC_EVENTS;<br>
> +<br>
> + if (slave->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)<br>
> + ctx->nc_clk_en = true;<br>
> +<br>
> + ret = sprd_dsi_find_panel(dsi);<br>
> + if (ret)<br>
> + return ret;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int sprd_dsi_host_detach(struct mipi_dsi_host *host,<br>
> + struct mipi_dsi_device *slave)<br>
> +{<br>
> + /* do nothing */<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static ssize_t sprd_dsi_host_transfer(struct mipi_dsi_host *host,<br>
> + const struct mipi_dsi_msg *msg)<br>
> +{<br>
> + struct sprd_dsi *dsi = host_to_dsi(host);<br>
> + const u8 *tx_buf = msg->tx_buf;<br>
> +<br>
> + if (msg->rx_buf && msg->rx_len) {<br>
> + u8 lsb = (msg->tx_len > 0) ? tx_buf[0] : 0;<br>
> + u8 msb = (msg->tx_len > 1) ? tx_buf[1] : 0;<br>
> +<br>
> + return sprd_dsi_rd_pkt(&dsi->ctx, msg->channel, msg->type,<br>
> + msb, lsb, msg->rx_buf, msg->rx_len);<br>
> + }<br>
> +<br>
> + if (msg->tx_buf && msg->tx_len)<br>
> + return sprd_dsi_wr_pkt(&dsi->ctx, msg->channel, msg->type,<br>
> + tx_buf, msg->tx_len);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct mipi_dsi_host_ops sprd_dsi_host_ops = {<br>
> + .attach = sprd_dsi_host_attach,<br>
> + .detach = sprd_dsi_host_detach,<br>
> + .transfer = sprd_dsi_host_transfer,<br>
> +};<br>
> +<br>
> +static int sprd_dsi_host_init(struct sprd_dsi *dsi, struct device *dev)<br>
> +{<br>
> + int ret;<br>
> +<br>
> + dsi-><a href="http://host.dev" rel="noreferrer" target="_blank">host.dev</a> = dev;<br>
> + dsi->host.ops = &sprd_dsi_host_ops;<br>
> +<br>
> + ret = mipi_dsi_host_register(&dsi->host);<br>
> + if (ret)<br>
> + drm_err(dsi->drm, "failed to register dsi host\n");<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static int sprd_dsi_connector_get_modes(struct drm_connector *connector)<br>
> +{<br>
> + struct sprd_dsi *dsi = connector_to_dsi(connector);<br>
> +<br>
> + return drm_panel_get_modes(dsi->panel, connector);<br>
> +}<br>
> +<br>
> +static enum drm_mode_status<br>
> +sprd_dsi_connector_mode_valid(struct drm_connector *connector,<br>
> + struct drm_display_mode *mode)<br>
> +{<br>
> + struct sprd_dsi *dsi = connector_to_dsi(connector);<br>
> +<br>
> + drm_dbg(dsi->drm, "%s() mode: "DRM_MODE_FMT"\n", __func__, DRM_MODE_ARG(mode));<br>
> +<br>
> + if (mode->type & DRM_MODE_TYPE_PREFERRED) {<br>
> + dsi->mode = mode;<br>
> + drm_display_mode_to_videomode(dsi->mode, &dsi->ctx.vm);<br>
> + }<br>
> +<br>
> + return MODE_OK;<br>
> +}<br>
> +<br>
> +static struct drm_encoder *<br>
> +sprd_dsi_connector_best_encoder(struct drm_connector *connector)<br>
> +{<br>
> + struct sprd_dsi *dsi = connector_to_dsi(connector);<br>
> +<br>
> + return &dsi->encoder;<br>
> +}<br>
> +<br>
> +static struct drm_connector_helper_funcs sprd_dsi_connector_helper_funcs = {<br>
> + .get_modes = sprd_dsi_connector_get_modes,<br>
> + .mode_valid = sprd_dsi_connector_mode_valid,<br>
> + .best_encoder = sprd_dsi_connector_best_encoder,<br>
> +};<br>
> +<br>
> +static enum drm_connector_status<br>
> +sprd_dsi_connector_detect(struct drm_connector *connector, bool force)<br>
> +{<br>
> + struct sprd_dsi *dsi = connector_to_dsi(connector);<br>
> +<br>
> + if (dsi->panel) {<br>
> + drm_panel_add(dsi->panel);<br>
> + return connector_status_connected;<br>
> + }<br>
> +<br>
> + return connector_status_disconnected;<br>
> +}<br>
> +<br>
> +static void sprd_dsi_connector_destroy(struct drm_connector *connector)<br>
> +{<br>
> + drm_connector_unregister(connector);<br>
> + drm_connector_cleanup(connector);<br>
> +}<br>
> +<br>
> +static const struct drm_connector_funcs sprd_dsi_atomic_connector_funcs = {<br>
> + .fill_modes = drm_helper_probe_single_connector_modes,<br>
> + .detect = sprd_dsi_connector_detect,<br>
> + .destroy = sprd_dsi_connector_destroy,<br>
> + .reset = drm_atomic_helper_connector_reset,<br>
> + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,<br>
> + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,<br>
> +};<br>
> +<br>
> +static int sprd_dsi_connector_init(struct drm_device *drm, struct sprd_dsi *dsi)<br>
> +{<br>
> + struct drm_encoder *encoder = &dsi->encoder;<br>
> + struct drm_connector *connector = &dsi->connector;<br>
> + int ret;<br>
> +<br>
> + connector->polled = DRM_CONNECTOR_POLL_HPD;<br>
> +<br>
> + ret = drm_connector_init(drm, connector,<br>
> + &sprd_dsi_atomic_connector_funcs,<br>
> + DRM_MODE_CONNECTOR_DSI);<br>
> + if (ret) {<br>
> + drm_err(drm, "drm_connector_init() failed\n");<br>
> + return ret;<br>
> + }<br>
> +<br>
> + drm_connector_helper_add(connector,<br>
> + &sprd_dsi_connector_helper_funcs);<br>
> +<br>
> + drm_connector_attach_encoder(connector, encoder);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static irqreturn_t sprd_dsi_isr(int irq, void *data)<br>
> +{<br>
> + struct sprd_dsi *dsi = data;<br>
> + u32 status = 0;<br>
> +<br>
> + if (dsi->ctx.irq0 == irq)<br>
> + status = sprd_dsi_int_status(&dsi->ctx, 0);<br>
> + else if (dsi->ctx.irq1 == irq)<br>
> + status = sprd_dsi_int_status(&dsi->ctx, 1);<br>
> +<br>
> + if (status & DSI_INT_STS_NEED_SOFT_RESET)<br>
> + sprd_dsi_state_reset(&dsi->ctx);<br>
> +<br>
> + return IRQ_HANDLED;<br>
> +}<br>
> +<br>
> +static int sprd_dsi_bind(struct device *dev, struct device *master, void *data)<br>
> +{<br>
> + struct drm_device *drm = data;<br>
> + struct sprd_dsi *dsi = dev_get_drvdata(dev);<br>
> + int ret;<br>
> +<br>
> + ret = sprd_dsi_encoder_init(drm, dsi);<br>
> + if (ret)<br>
> + goto cleanup_host;<br>
> +<br>
> + ret = sprd_dsi_connector_init(drm, dsi);<br>
> + if (ret)<br>
> + goto cleanup_encoder;<br>
> +<br>
> + dsi->drm = drm;<br>
> +<br>
> + return 0;<br>
> +<br>
> +cleanup_encoder:<br>
> + drm_encoder_cleanup(&dsi->encoder);<br>
> +cleanup_host:<br>
> + mipi_dsi_host_unregister(&dsi->host);<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static void sprd_dsi_unbind(struct device *dev,<br>
> + struct device *master, void *data)<br>
> +{<br>
> + struct drm_device *drm = data;<br>
> +<br>
> + /* do nothing */<br>
> + drm_dbg(drm, "%s()\n", __func__);<br>
> +<br>
> +}<br>
> +<br>
> +static const struct component_ops dsi_component_ops = {<br>
> + .bind = sprd_dsi_bind,<br>
> + .unbind = sprd_dsi_unbind,<br>
> +};<br>
> +<br>
> +static int sprd_dsi_context_init(struct sprd_dsi *dsi,<br>
> + struct device *dev)<br>
> +{<br>
> + struct platform_device *pdev = to_platform_device(dev);<br>
> + struct dsi_context *ctx = &dsi->ctx;<br>
> + struct resource *res;<br>
> + int ret;<br>
> +<br>
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);<br>
> + ctx->base = devm_ioremap(dev, res->start, resource_size(res));<br>
> + if (!ctx->base) {<br>
> + drm_err(dsi->drm, "failed to map dsi host registers\n");<br>
> + return -ENXIO;<br>
> + }<br>
> +<br>
> + ctx->pll = devm_kzalloc(dev, sizeof(*ctx->pll), GFP_KERNEL);<br>
<br>
You probably want to use drmm_kzalloc here, just to be on the safe side.<br>
<br>
> + if (!ctx->pll) {<br>
> + drm_err(dsi->drm, "failed to allocate dphy pll data.\n");<br>
> + return -ENOMEM;<br>
> + }<br>
> +<br>
> + ctx->regmap = devm_regmap_init(dev, ®map_tst_io, dsi, &byte_config);<br>
> + if (IS_ERR(ctx->regmap)) {<br>
> + drm_err(dsi->drm, "dphy regmap init failed\n");<br>
> + return PTR_ERR(ctx->regmap);<br>
> + }<br>
> +<br>
> + ctx->irq0 = platform_get_irq(pdev, 0);<br>
> + if (ctx->irq0 > 0) {<br>
> + ret = request_irq(ctx->irq0, sprd_dsi_isr, 0, "DSI_INT0", dsi);<br>
> + if (ret) {<br>
> + drm_err(dsi->drm, "failed to request dsi irq int0!\n");<br>
> + return -EINVAL;<br>
> + }<br>
> + }<br>
> +<br>
> + ctx->irq1 = platform_get_irq(pdev, 1);<br>
> + if (ctx->irq1 > 0) {<br>
> + ret = request_irq(ctx->irq1, sprd_dsi_isr, 0, "DSI_INT1", dsi);<br>
> + if (ret) {<br>
> + drm_err(dsi->drm, "failed to request dsi irq int1!\n");<br>
> + return -EINVAL;<br>
> + }<br>
> + }<br>
> +<br>
> + ctx->data_hs2lp = 120;<br>
> + ctx->data_lp2hs = 500;<br>
> + ctx->clk_hs2lp = 4;<br>
> + ctx->clk_lp2hs = 15;<br>
> + ctx->max_rd_time = 6000;<br>
> + ctx->int0_mask = 0xffffffff;<br>
> + ctx->int1_mask = 0xffffffff;<br>
> +<br>
> + dsi->ctx.enabled = true;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct of_device_id dsi_match_table[] = {<br>
> + { .compatible = "sprd,sharkl3-dsi-host" },<br>
> + { /* sentinel */ },<br>
> +};<br>
> +<br>
> +static int sprd_dsi_probe(struct platform_device *pdev)<br>
> +{<br>
> + struct sprd_dsi *dsi;<br>
> + int ret;<br>
> +<br>
> + dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);<br>
> + if (!dsi) {<br>
> + dev_err(&pdev->dev, "failed to allocate dsi data.\n");<br>
> + return -ENOMEM;<br>
> + }<br>
> +<br>
> + dsi->dev = &pdev->dev;<br>
> +<br>
> + ret = sprd_dsi_context_init(dsi, &pdev->dev);<br>
> + if (ret)<br>
> + goto err;<br>
> +<br>
> + ret = sprd_dsi_host_init(dsi, &pdev->dev);<br>
> + if (ret)<br>
> + goto err;<br>
<br>
Same comment as with the previous patch for planes/crtc: If you move this<br>
into the bind function then you can use the drmm_ functions and ditch the<br>
kfree.<br>
<br>
> +<br>
> + platform_set_drvdata(pdev, dsi);<br>
> +<br>
> + return component_add(&pdev->dev, &dsi_component_ops);<br>
> +<br>
> +err:<br>
> + kfree(dsi);<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static int sprd_dsi_remove(struct platform_device *pdev)<br>
> +{<br>
> + struct sprd_dsi *dsi = platform_get_drvdata(pdev);<br>
> +<br>
> + component_del(&pdev->dev, &dsi_component_ops);<br>
> +<br>
> + kfree(dsi);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +struct platform_driver sprd_dsi_driver = {<br>
> + .probe = sprd_dsi_probe,<br>
> + .remove = sprd_dsi_remove,<br>
> + .driver = {<br>
> + .name = "sprd-dsi-drv",<br>
> + .of_match_table = dsi_match_table,<br>
> + },<br>
> +};<br>
> +<br>
> +MODULE_AUTHOR("Leon He <<a href="mailto:leon.he@unisoc.com" target="_blank">leon.he@unisoc.com</a>>");<br>
> +MODULE_AUTHOR("Kevin Tang <<a href="mailto:kevin.tang@unisoc.com" target="_blank">kevin.tang@unisoc.com</a>>");<br>
> +MODULE_DESCRIPTION("Unisoc MIPI DSI HOST Controller Driver");<br>
> +MODULE_LICENSE("GPL v2");<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_dsi.h b/drivers/gpu/drm/sprd/sprd_dsi.h<br>
> new file mode 100644<br>
> index 0000000..e07cd12<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_dsi.h<br>
> @@ -0,0 +1,107 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2020 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#ifndef __SPRD_DSI_H__<br>
> +#define __SPRD_DSI_H__<br>
> +<br>
> +#include <linux/of.h><br>
> +#include <linux/device.h><br>
> +#include <linux/regmap.h><br>
> +#include <video/videomode.h><br>
> +<br>
> +#include <drm/drm_bridge.h><br>
> +#include <drm/drm_connector.h><br>
> +#include <drm/drm_encoder.h><br>
> +#include <drm/drm_mipi_dsi.h><br>
> +#include <drm/drm_print.h><br>
> +#include <drm/drm_panel.h><br>
> +<br>
> +#include "megacores_pll.h"<br>
> +<br>
> +#define DSI_INT_STS_NEED_SOFT_RESET BIT(0)<br>
> +#define DSI_INT_STS_NEED_HARD_RESET BIT(1)<br>
> +<br>
> +enum dsi_work_mode {<br>
> + DSI_MODE_CMD = 0,<br>
> + DSI_MODE_VIDEO<br>
> +};<br>
> +<br>
> +enum video_burst_mode {<br>
> + VIDEO_NON_BURST_WITH_SYNC_PULSES = 0,<br>
> + VIDEO_NON_BURST_WITH_SYNC_EVENTS,<br>
> + VIDEO_BURST_WITH_SYNC_PULSES<br>
> +};<br>
> +<br>
> +enum dsi_color_coding {<br>
> + COLOR_CODE_16BIT_CONFIG1 = 0,<br>
> + COLOR_CODE_16BIT_CONFIG2,<br>
> + COLOR_CODE_16BIT_CONFIG3,<br>
> + COLOR_CODE_18BIT_CONFIG1,<br>
> + COLOR_CODE_18BIT_CONFIG2,<br>
> + COLOR_CODE_24BIT,<br>
> + COLOR_CODE_20BIT_YCC422_LOOSELY,<br>
> + COLOR_CODE_24BIT_YCC422,<br>
> + COLOR_CODE_16BIT_YCC422,<br>
> + COLOR_CODE_30BIT,<br>
> + COLOR_CODE_36BIT,<br>
> + COLOR_CODE_12BIT_YCC420,<br>
> + COLOR_CODE_COMPRESSTION,<br>
> + COLOR_CODE_MAX<br>
> +};<br>
> +<br>
> +struct dsi_context {<br>
> + void __iomem *base;<br>
> + struct regmap *regmap;<br>
> + struct dphy_pll *pll;<br>
> + struct videomode vm;<br>
> + bool enabled;<br>
> +<br>
> + u8 lanes;<br>
> + u32 format;<br>
> + u8 work_mode;<br>
> + u8 burst_mode;<br>
> +<br>
> + int irq0;<br>
> + int irq1;<br>
> + u32 int0_mask;<br>
> + u32 int1_mask;<br>
> +<br>
> + /* byte clock [KHz] */<br>
> + u32 byte_clk;<br>
> + /* escape clock [KHz] */<br>
> + u32 esc_clk;<br>
> + /* maximum time (ns) for data lanes from HS to LP */<br>
> + u16 data_hs2lp;<br>
> + /* maximum time (ns) for data lanes from LP to HS */<br>
> + u16 data_lp2hs;<br>
> + /* maximum time (ns) for clk lanes from HS to LP */<br>
> + u16 clk_hs2lp;<br>
> + /* maximum time (ns) for clk lanes from LP to HS */<br>
> + u16 clk_lp2hs;<br>
> + /* maximum time (ns) for BTA operation - REQUIRED */<br>
> + u16 max_rd_time;<br>
> + /* is 18-bit loosely packets (valid only when BPP == 18) */<br>
> + bool is_18_loosely;<br>
> + /* enable receiving frame ack packets - for video mode */<br>
> + bool frame_ack_en;<br>
> + /* enable receiving tear effect ack packets - for cmd mode */<br>
> + bool te_ack_en;<br>
> + /* enable non coninuous clock for energy saving */<br>
> + bool nc_clk_en;<br>
> +};<br>
> +<br>
> +struct sprd_dsi {<br>
> + struct device *dev;<br>
> + struct drm_device *drm;<br>
> + struct mipi_dsi_host host;<br>
> + struct mipi_dsi_device *slave;<br>
> + struct drm_encoder encoder;<br>
> + struct drm_connector connector;<br>
> + struct drm_panel *panel;<br>
> + struct drm_display_mode *mode;<br>
> + struct dsi_context ctx;<br>
> +};<br>
> +<br>
> +#endif /* __SPRD_DSI_H__ */<br>
> -- <br>
> 2.7.4<br>
> <br>
<br>
-- <br>
Daniel Vetter<br>
Software Engineer, Intel Corporation<br>
<a href="http://blog.ffwll.ch" rel="noreferrer" target="_blank">http://blog.ffwll.ch</a><br>
</blockquote></div></div>