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 #include <drm/drm_panel.h> 16 17 #include "msm_drv.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_DEV_REGULATOR_MAX 8 33 #define DSI_BUS_CLK_MAX 4 34 35 /* Regulators for DSI devices */ 36 struct dsi_reg_entry { 37 char name[32]; 38 int enable_load; 39 int disable_load; 40 }; 41 42 struct dsi_reg_config { 43 int num; 44 struct dsi_reg_entry regs[DSI_DEV_REGULATOR_MAX]; 45 }; 46 47 struct msm_dsi { 48 struct drm_device *dev; 49 struct platform_device *pdev; 50 51 /* connector managed by us when we're connected to a drm_panel */ 52 struct drm_connector *connector; 53 /* internal dsi bridge attached to MDP interface */ 54 struct drm_bridge *bridge; 55 56 struct mipi_dsi_host *host; 57 struct msm_dsi_phy *phy; 58 59 /* 60 * panel/external_bridge connected to dsi bridge output, only one of the 61 * two can be valid at a time 62 */ 63 struct drm_panel *panel; 64 struct drm_bridge *external_bridge; 65 66 struct device *phy_dev; 67 bool phy_enabled; 68 69 /* the encoder we are hooked to (outside of dsi block) */ 70 struct drm_encoder *encoder; 71 72 int id; 73 }; 74 75 /* dsi manager */ 76 struct drm_bridge *msm_dsi_manager_bridge_init(u8 id); 77 void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge); 78 struct drm_connector *msm_dsi_manager_connector_init(u8 id); 79 struct drm_connector *msm_dsi_manager_ext_bridge_init(u8 id); 80 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg); 81 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len); 82 void msm_dsi_manager_setup_encoder(int id); 83 int msm_dsi_manager_register(struct msm_dsi *msm_dsi); 84 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi); 85 bool msm_dsi_manager_validate_current_config(u8 id); 86 87 /* msm dsi */ 88 static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi) 89 { 90 return msm_dsi->panel || msm_dsi->external_bridge; 91 } 92 93 struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi); 94 95 /* dsi pll */ 96 struct msm_dsi_pll; 97 #ifdef CONFIG_DRM_MSM_DSI_PLL 98 void msm_dsi_pll_destroy(struct msm_dsi_pll *pll); 99 int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll, 100 struct clk **byte_clk_provider, struct clk **pixel_clk_provider); 101 void msm_dsi_pll_save_state(struct msm_dsi_pll *pll); 102 int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll); 103 int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll, 104 enum msm_dsi_phy_usecase uc); 105 #else 106 static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll) 107 { 108 } 109 static inline int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll, 110 struct clk **byte_clk_provider, struct clk **pixel_clk_provider) 111 { 112 return -ENODEV; 113 } 114 static inline void msm_dsi_pll_save_state(struct msm_dsi_pll *pll) 115 { 116 } 117 static inline int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll) 118 { 119 return 0; 120 } 121 static inline int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll, 122 enum msm_dsi_phy_usecase uc) 123 { 124 return -ENODEV; 125 } 126 #endif 127 128 /* dsi host */ 129 struct msm_dsi_host; 130 int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host, 131 const struct mipi_dsi_msg *msg); 132 void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host, 133 const struct mipi_dsi_msg *msg); 134 int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host, 135 const struct mipi_dsi_msg *msg); 136 int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host, 137 const struct mipi_dsi_msg *msg); 138 void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host, 139 u32 dma_base, u32 len); 140 int msm_dsi_host_enable(struct mipi_dsi_host *host); 141 int msm_dsi_host_disable(struct mipi_dsi_host *host); 142 int msm_dsi_host_power_on(struct mipi_dsi_host *host, 143 struct msm_dsi_phy_shared_timings *phy_shared_timings, 144 bool is_dual_dsi); 145 int msm_dsi_host_power_off(struct mipi_dsi_host *host); 146 int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host, 147 const struct drm_display_mode *mode); 148 struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host); 149 unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host); 150 struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host); 151 int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer); 152 void msm_dsi_host_unregister(struct mipi_dsi_host *host); 153 int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host, 154 struct msm_dsi_pll *src_pll); 155 void msm_dsi_host_reset_phy(struct mipi_dsi_host *host); 156 void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host, 157 struct msm_dsi_phy_clk_request *clk_req, 158 bool is_dual_dsi); 159 void msm_dsi_host_destroy(struct mipi_dsi_host *host); 160 int msm_dsi_host_modeset_init(struct mipi_dsi_host *host, 161 struct drm_device *dev); 162 int msm_dsi_host_init(struct msm_dsi *msm_dsi); 163 int msm_dsi_runtime_suspend(struct device *dev); 164 int msm_dsi_runtime_resume(struct device *dev); 165 int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host); 166 int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host); 167 int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host); 168 int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host); 169 void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host); 170 void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host); 171 int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size); 172 int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); 173 void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host); 174 void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host); 175 void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host); 176 int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova); 177 int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova); 178 int dsi_clk_init_v2(struct msm_dsi_host *msm_host); 179 int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host); 180 int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_dual_dsi); 181 int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_dual_dsi); 182 183 /* dsi phy */ 184 struct msm_dsi_phy; 185 struct msm_dsi_phy_shared_timings { 186 u32 clk_post; 187 u32 clk_pre; 188 bool clk_pre_inc_by_2; 189 }; 190 191 struct msm_dsi_phy_clk_request { 192 unsigned long bitclk_rate; 193 unsigned long escclk_rate; 194 }; 195 196 void msm_dsi_phy_driver_register(void); 197 void msm_dsi_phy_driver_unregister(void); 198 int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int src_pll_id, 199 struct msm_dsi_phy_clk_request *clk_req); 200 void msm_dsi_phy_disable(struct msm_dsi_phy *phy); 201 void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy *phy, 202 struct msm_dsi_phy_shared_timings *shared_timing); 203 struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy); 204 void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy, 205 enum msm_dsi_phy_usecase uc); 206 207 #endif /* __DSI_CONNECTOR_H__ */ 208 209