1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2015, The Linux Foundation. All rights reserved. 4 */ 5 6 #ifndef __DSI_CONNECTOR_H__ 7 #define __DSI_CONNECTOR_H__ 8 9 #include <linux/of_platform.h> 10 #include <linux/platform_device.h> 11 12 #include <drm/drm_bridge.h> 13 #include <drm/drm_crtc.h> 14 #include <drm/drm_mipi_dsi.h> 15 16 #include "msm_drv.h" 17 #include "disp/msm_disp_snapshot.h" 18 19 #define DSI_0 0 20 #define DSI_1 1 21 #define DSI_MAX 2 22 23 struct msm_dsi_phy_shared_timings; 24 struct msm_dsi_phy_clk_request; 25 26 enum msm_dsi_phy_usecase { 27 MSM_DSI_PHY_STANDALONE, 28 MSM_DSI_PHY_MASTER, 29 MSM_DSI_PHY_SLAVE, 30 }; 31 32 #define DSI_BUS_CLK_MAX 4 33 34 struct msm_dsi { 35 struct drm_device *dev; 36 struct platform_device *pdev; 37 38 struct mipi_dsi_host *host; 39 struct msm_dsi_phy *phy; 40 41 struct device *phy_dev; 42 bool phy_enabled; 43 44 int id; 45 }; 46 47 /* dsi manager */ 48 struct drm_bridge *msm_dsi_manager_bridge_init(struct msm_dsi *msm_dsi, 49 struct drm_encoder *encoder); 50 int msm_dsi_manager_ext_bridge_init(u8 id, struct drm_bridge *int_bridge); 51 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg); 52 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len); 53 int msm_dsi_manager_register(struct msm_dsi *msm_dsi); 54 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi); 55 void msm_dsi_manager_tpg_enable(void); 56 57 /* dsi host */ 58 struct msm_dsi_host; 59 int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host, 60 const struct mipi_dsi_msg *msg); 61 void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host, 62 const struct mipi_dsi_msg *msg); 63 int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host, 64 const struct mipi_dsi_msg *msg); 65 int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host, 66 const struct mipi_dsi_msg *msg); 67 void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host, 68 u32 dma_base, u32 len); 69 int msm_dsi_host_enable(struct mipi_dsi_host *host); 70 int msm_dsi_host_disable(struct mipi_dsi_host *host); 71 void msm_dsi_host_enable_irq(struct mipi_dsi_host *host); 72 void msm_dsi_host_disable_irq(struct mipi_dsi_host *host); 73 int msm_dsi_host_power_on(struct mipi_dsi_host *host, 74 struct msm_dsi_phy_shared_timings *phy_shared_timings, 75 bool is_bonded_dsi, struct msm_dsi_phy *phy); 76 int msm_dsi_host_power_off(struct mipi_dsi_host *host); 77 int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host, 78 const struct drm_display_mode *mode); 79 enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host, 80 const struct drm_display_mode *mode); 81 unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host); 82 int msm_dsi_host_register(struct mipi_dsi_host *host); 83 void msm_dsi_host_unregister(struct mipi_dsi_host *host); 84 void msm_dsi_host_set_phy_mode(struct mipi_dsi_host *host, 85 struct msm_dsi_phy *src_phy); 86 int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host, 87 struct msm_dsi_phy *src_phy); 88 void msm_dsi_host_reset_phy(struct mipi_dsi_host *host); 89 void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host, 90 struct msm_dsi_phy_clk_request *clk_req, 91 bool is_bonded_dsi); 92 void msm_dsi_host_destroy(struct mipi_dsi_host *host); 93 int msm_dsi_host_modeset_init(struct mipi_dsi_host *host, 94 struct drm_device *dev); 95 int msm_dsi_host_init(struct msm_dsi *msm_dsi); 96 int msm_dsi_runtime_suspend(struct device *dev); 97 int msm_dsi_runtime_resume(struct device *dev); 98 int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host); 99 int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host); 100 int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host); 101 int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host); 102 void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host); 103 void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host); 104 unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi, 105 const struct drm_display_mode *mode); 106 int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size); 107 int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); 108 void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host); 109 void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host); 110 void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host); 111 void msm_dsi_tx_buf_free(struct mipi_dsi_host *mipi_host); 112 int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova); 113 int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova); 114 int dsi_clk_init_v2(struct msm_dsi_host *msm_host); 115 int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host); 116 int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi); 117 int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi); 118 void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host); 119 void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host); 120 struct drm_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host); 121 bool msm_dsi_host_is_wide_bus_enabled(struct mipi_dsi_host *host); 122 123 /* dsi phy */ 124 struct msm_dsi_phy; 125 struct msm_dsi_phy_shared_timings { 126 u32 clk_post; 127 u32 clk_pre; 128 bool clk_pre_inc_by_2; 129 bool byte_intf_clk_div_2; 130 }; 131 132 struct msm_dsi_phy_clk_request { 133 unsigned long bitclk_rate; 134 unsigned long escclk_rate; 135 }; 136 137 void msm_dsi_phy_driver_register(void); 138 void msm_dsi_phy_driver_unregister(void); 139 int msm_dsi_phy_enable(struct msm_dsi_phy *phy, 140 struct msm_dsi_phy_clk_request *clk_req, 141 struct msm_dsi_phy_shared_timings *shared_timings); 142 void msm_dsi_phy_disable(struct msm_dsi_phy *phy); 143 void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy, 144 enum msm_dsi_phy_usecase uc); 145 void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy); 146 int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy); 147 void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct msm_dsi_phy *phy); 148 bool msm_dsi_phy_set_continuous_clock(struct msm_dsi_phy *phy, bool enable); 149 150 #endif /* __DSI_CONNECTOR_H__ */ 151 152