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