Re: [PATCH v7 3/4] drm/kmb: Mipi DSI part of the display driver

2020-09-10 Thread Daniel Vetter
On Mon, Aug 31, 2020 at 01:02:51PM -0700, Anitha Chrisanthus wrote:
> Initializes Mipi DSI and sets up connects to ADV bridge
> 
> v2: removed license text
> upclassed dev_private, removed HAVE_IRQ. (Sam)
> 
> v3: Squashed all 59 commits to one
> 
> v4: review changes from Sam Ravnborg
>   renamed dev_p to kmb
> 
> v5: corrected spellings
> v6: corrected checkpatch warnings
> v7: review changes Sam Ravnborg and Thomas Zimmerman
>   removed unnecessary logs and defines and ifdef codes (Sam)
>   split dphy_init_sequence smaller (Sam)
>   removed redundant checks in kmb_dsi (Sam)
>   changed kmb_dsi_init to drm_bridge_connector_init and

There's still a ton of leftover and now dead code for the old
dsi_connector you've had. Please remove.

Another comment/question below.


>   drm_connector_attach_encoder to bridge's connector (Sam)
> 
> Cc: Sam Ravnborg 
> Signed-off-by: Anitha Chrisanthus 
> Reviewed-by: Bob Paauwe 
> ---
>  drivers/gpu/drm/kmb/kmb_dsi.c | 1523 
> +
>  drivers/gpu/drm/kmb/kmb_dsi.h |  350 ++
>  2 files changed, 1873 insertions(+)
>  create mode 100644 drivers/gpu/drm/kmb/kmb_dsi.c
>  create mode 100644 drivers/gpu/drm/kmb/kmb_dsi.h
> 
> diff --git a/drivers/gpu/drm/kmb/kmb_dsi.c b/drivers/gpu/drm/kmb/kmb_dsi.c
> new file mode 100644
> index 000..a0dbfa7
> --- /dev/null
> +++ b/drivers/gpu/drm/kmb/kmb_dsi.c
> @@ -0,0 +1,1523 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright © 2019-2020 Intel Corporation
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "kmb_drv.h"
> +#include "kmb_dsi.h"
> +#include "kmb_regs.h"
> +
> +static struct mipi_dsi_host *dsi_host;
> +static struct mipi_dsi_device *dsi_device;
> +
> +/* Default setting is 1080p, 4 lanes */
> +#define IMG_HEIGHT_LINES  1080
> +#define IMG_WIDTH_PX  1920
> +#define MIPI_TX_ACTIVE_LANES 4
> +
> +struct mipi_tx_frame_section_cfg mipi_tx_frame0_sect_cfg = {
> + .width_pixels = IMG_WIDTH_PX,
> + .height_lines = IMG_HEIGHT_LINES,
> + .data_type = DSI_LP_DT_PPS_RGB888_24B,
> + .data_mode = MIPI_DATA_MODE1,
> + .dma_packed = 0
> +};
> +
> +struct mipi_tx_frame_cfg mipitx_frame0_cfg = {
> + .sections[0] = _tx_frame0_sect_cfg,
> + .sections[1] = NULL,
> + .sections[2] = NULL,
> + .sections[3] = NULL,
> + .vsync_width = 5,
> + .v_backporch = 36,
> + .v_frontporch = 4,
> + .hsync_width = 44,
> + .h_backporch = 148,
> + .h_frontporch = 88
> +};
> +
> +struct mipi_tx_dsi_cfg mipitx_dsi_cfg = {
> + .hfp_blank_en = 0,
> + .eotp_en = 0,
> + .lpm_last_vfp_line = 0,
> + .lpm_first_vsa_line = 0,
> + .sync_pulse_eventn = DSI_VIDEO_MODE_NO_BURST_EVENT,
> + .hfp_blanking = SEND_BLANK_PACKET,
> + .hbp_blanking = SEND_BLANK_PACKET,
> + .hsa_blanking = SEND_BLANK_PACKET,
> + .v_blanking = SEND_BLANK_PACKET,
> +};
> +
> +struct mipi_ctrl_cfg mipi_tx_init_cfg = {
> + .active_lanes = MIPI_TX_ACTIVE_LANES,
> + .lane_rate_mbps = MIPI_TX_LANE_DATA_RATE_MBPS,
> + .ref_clk_khz = MIPI_TX_REF_CLK_KHZ,
> + .cfg_clk_khz = MIPI_TX_CFG_CLK_KHZ,
> + .tx_ctrl_cfg = {
> + .frames[0] = _frame0_cfg,
> + .frames[1] = NULL,
> + .frames[2] = NULL,
> + .frames[3] = NULL,
> + .tx_dsi_cfg = _dsi_cfg,
> + .line_sync_pkt_en = 0,
> + .line_counter_active = 0,
> + .frame_counter_active = 0,
> + .tx_always_use_hact = 1,
> + .tx_hact_wait_stop = 1,
> + }
> +};
> +
> +struct  mipi_hs_freq_range_cfg {
> + u16 default_bit_rate_mbps;
> + u8 hsfreqrange_code;
> +};
> +
> +struct vco_params {
> + u32 freq;
> + u32 range;
> + u32 divider;
> +};
> +
> +static struct vco_params vco_table[] = {
> + {52, 0x3f, 8},
> + {80, 0x39, 8},
> + {105, 0x2f, 4},
> + {160, 0x29, 4},
> + {210, 0x1f, 2},
> + {320, 0x19, 2},
> + {420, 0x0f, 1},
> + {630, 0x09, 1},
> + {1100, 0x03, 1},
> + {0x, 0x01, 1},
> +};
> +
> +static struct mipi_hs_freq_range_cfg
> +mipi_hs_freq_range[MIPI_DPHY_DEFAULT_BIT_RATES] = {
> + {.default_bit_rate_mbps = 80, .hsfreqrange_code = 0x00},
> + {.default_bit_rate_mbps = 90, .hsfreqrange_code = 0x10},
> + {.default_bit_rate_mbps = 100, .hsfreqrange_code = 0x20},
> + {.default_bit_rate_mbps = 110, .hsfreqrange_code = 0x30},
> + {.default_bit_rate_mbps = 120, .hsfreqrange_code = 0x01},
> + {.default_bit_rate_mbps = 130, .hsfreqrange_code = 0x11},
> + {.default_bit_rate_mbps = 140, .hsfreqrange_code = 0x21},
> + {.default_bit_rate_mbps = 150, .hsfreqrange_code = 0x31},
> + {.default_bit_rate_mbps = 160, 

[PATCH v7 3/4] drm/kmb: Mipi DSI part of the display driver

2020-08-31 Thread Anitha Chrisanthus
Initializes Mipi DSI and sets up connects to ADV bridge

v2: removed license text
upclassed dev_private, removed HAVE_IRQ. (Sam)

v3: Squashed all 59 commits to one

v4: review changes from Sam Ravnborg
renamed dev_p to kmb

v5: corrected spellings
v6: corrected checkpatch warnings
v7: review changes Sam Ravnborg and Thomas Zimmerman
removed unnecessary logs and defines and ifdef codes (Sam)
split dphy_init_sequence smaller (Sam)
removed redundant checks in kmb_dsi (Sam)
changed kmb_dsi_init to drm_bridge_connector_init and
drm_connector_attach_encoder to bridge's connector (Sam)

Cc: Sam Ravnborg 
Signed-off-by: Anitha Chrisanthus 
Reviewed-by: Bob Paauwe 
---
 drivers/gpu/drm/kmb/kmb_dsi.c | 1523 +
 drivers/gpu/drm/kmb/kmb_dsi.h |  350 ++
 2 files changed, 1873 insertions(+)
 create mode 100644 drivers/gpu/drm/kmb/kmb_dsi.c
 create mode 100644 drivers/gpu/drm/kmb/kmb_dsi.h

diff --git a/drivers/gpu/drm/kmb/kmb_dsi.c b/drivers/gpu/drm/kmb/kmb_dsi.c
new file mode 100644
index 000..a0dbfa7
--- /dev/null
+++ b/drivers/gpu/drm/kmb/kmb_dsi.c
@@ -0,0 +1,1523 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright © 2019-2020 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kmb_drv.h"
+#include "kmb_dsi.h"
+#include "kmb_regs.h"
+
+static struct mipi_dsi_host *dsi_host;
+static struct mipi_dsi_device *dsi_device;
+
+/* Default setting is 1080p, 4 lanes */
+#define IMG_HEIGHT_LINES  1080
+#define IMG_WIDTH_PX  1920
+#define MIPI_TX_ACTIVE_LANES 4
+
+struct mipi_tx_frame_section_cfg mipi_tx_frame0_sect_cfg = {
+   .width_pixels = IMG_WIDTH_PX,
+   .height_lines = IMG_HEIGHT_LINES,
+   .data_type = DSI_LP_DT_PPS_RGB888_24B,
+   .data_mode = MIPI_DATA_MODE1,
+   .dma_packed = 0
+};
+
+struct mipi_tx_frame_cfg mipitx_frame0_cfg = {
+   .sections[0] = _tx_frame0_sect_cfg,
+   .sections[1] = NULL,
+   .sections[2] = NULL,
+   .sections[3] = NULL,
+   .vsync_width = 5,
+   .v_backporch = 36,
+   .v_frontporch = 4,
+   .hsync_width = 44,
+   .h_backporch = 148,
+   .h_frontporch = 88
+};
+
+struct mipi_tx_dsi_cfg mipitx_dsi_cfg = {
+   .hfp_blank_en = 0,
+   .eotp_en = 0,
+   .lpm_last_vfp_line = 0,
+   .lpm_first_vsa_line = 0,
+   .sync_pulse_eventn = DSI_VIDEO_MODE_NO_BURST_EVENT,
+   .hfp_blanking = SEND_BLANK_PACKET,
+   .hbp_blanking = SEND_BLANK_PACKET,
+   .hsa_blanking = SEND_BLANK_PACKET,
+   .v_blanking = SEND_BLANK_PACKET,
+};
+
+struct mipi_ctrl_cfg mipi_tx_init_cfg = {
+   .active_lanes = MIPI_TX_ACTIVE_LANES,
+   .lane_rate_mbps = MIPI_TX_LANE_DATA_RATE_MBPS,
+   .ref_clk_khz = MIPI_TX_REF_CLK_KHZ,
+   .cfg_clk_khz = MIPI_TX_CFG_CLK_KHZ,
+   .tx_ctrl_cfg = {
+   .frames[0] = _frame0_cfg,
+   .frames[1] = NULL,
+   .frames[2] = NULL,
+   .frames[3] = NULL,
+   .tx_dsi_cfg = _dsi_cfg,
+   .line_sync_pkt_en = 0,
+   .line_counter_active = 0,
+   .frame_counter_active = 0,
+   .tx_always_use_hact = 1,
+   .tx_hact_wait_stop = 1,
+   }
+};
+
+struct  mipi_hs_freq_range_cfg {
+   u16 default_bit_rate_mbps;
+   u8 hsfreqrange_code;
+};
+
+struct vco_params {
+   u32 freq;
+   u32 range;
+   u32 divider;
+};
+
+static struct vco_params vco_table[] = {
+   {52, 0x3f, 8},
+   {80, 0x39, 8},
+   {105, 0x2f, 4},
+   {160, 0x29, 4},
+   {210, 0x1f, 2},
+   {320, 0x19, 2},
+   {420, 0x0f, 1},
+   {630, 0x09, 1},
+   {1100, 0x03, 1},
+   {0x, 0x01, 1},
+};
+
+static struct mipi_hs_freq_range_cfg
+mipi_hs_freq_range[MIPI_DPHY_DEFAULT_BIT_RATES] = {
+   {.default_bit_rate_mbps = 80, .hsfreqrange_code = 0x00},
+   {.default_bit_rate_mbps = 90, .hsfreqrange_code = 0x10},
+   {.default_bit_rate_mbps = 100, .hsfreqrange_code = 0x20},
+   {.default_bit_rate_mbps = 110, .hsfreqrange_code = 0x30},
+   {.default_bit_rate_mbps = 120, .hsfreqrange_code = 0x01},
+   {.default_bit_rate_mbps = 130, .hsfreqrange_code = 0x11},
+   {.default_bit_rate_mbps = 140, .hsfreqrange_code = 0x21},
+   {.default_bit_rate_mbps = 150, .hsfreqrange_code = 0x31},
+   {.default_bit_rate_mbps = 160, .hsfreqrange_code = 0x02},
+   {.default_bit_rate_mbps = 170, .hsfreqrange_code = 0x12},
+   {.default_bit_rate_mbps = 180, .hsfreqrange_code = 0x22},
+   {.default_bit_rate_mbps = 190, .hsfreqrange_code = 0x32},
+   {.default_bit_rate_mbps = 205, .hsfreqrange_code = 0x03},
+   {.default_bit_rate_mbps = 220, .hsfreqrange_code = 0x13},
+