1 /* 2 * Copyright (c) 2015, The Linux Foundation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 2 and 6 * only version 2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 */ 13 14 #ifndef __DSI_CONNECTOR_H__ 15 #define __DSI_CONNECTOR_H__ 16 17 #include <linux/platform_device.h> 18 19 #include "drm_crtc.h" 20 #include "drm_mipi_dsi.h" 21 #include "drm_panel.h" 22 23 #include "msm_drv.h" 24 25 #define DSI_0 0 26 #define DSI_1 1 27 #define DSI_MAX 2 28 29 #define DSI_CLOCK_MASTER DSI_0 30 #define DSI_CLOCK_SLAVE DSI_1 31 32 #define DSI_LEFT DSI_0 33 #define DSI_RIGHT DSI_1 34 35 /* According to the current drm framework sequence, take the encoder of 36 * DSI_1 as master encoder 37 */ 38 #define DSI_ENCODER_MASTER DSI_1 39 #define DSI_ENCODER_SLAVE DSI_0 40 41 enum msm_dsi_phy_type { 42 MSM_DSI_PHY_UNKNOWN, 43 MSM_DSI_PHY_28NM_HPM, 44 MSM_DSI_PHY_28NM_LP, 45 MSM_DSI_PHY_MAX 46 }; 47 48 struct msm_dsi { 49 struct drm_device *dev; 50 struct platform_device *pdev; 51 52 struct drm_connector *connector; 53 struct drm_bridge *bridge; 54 55 struct mipi_dsi_host *host; 56 struct msm_dsi_phy *phy; 57 struct drm_panel *panel; 58 unsigned long panel_flags; 59 60 enum msm_dsi_phy_type phy_type; 61 bool phy_enabled; 62 63 /* the encoders we are hooked to (outside of dsi block) */ 64 struct drm_encoder *encoders[MSM_DSI_ENCODER_NUM]; 65 66 int id; 67 }; 68 69 /* dsi manager */ 70 struct drm_bridge *msm_dsi_manager_bridge_init(u8 id); 71 void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge); 72 struct drm_connector *msm_dsi_manager_connector_init(u8 id); 73 int msm_dsi_manager_phy_enable(int id, 74 const unsigned long bit_rate, const unsigned long esc_rate, 75 u32 *clk_pre, u32 *clk_post); 76 void msm_dsi_manager_phy_disable(int id); 77 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg); 78 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 iova, u32 len); 79 int msm_dsi_manager_register(struct msm_dsi *msm_dsi); 80 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi); 81 82 /* msm dsi */ 83 struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi); 84 85 /* dsi pll */ 86 struct msm_dsi_pll; 87 #ifdef CONFIG_DRM_MSM_DSI_PLL 88 struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev, 89 enum msm_dsi_phy_type type, int dsi_id); 90 void msm_dsi_pll_destroy(struct msm_dsi_pll *pll); 91 int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll, 92 struct clk **byte_clk_provider, struct clk **pixel_clk_provider); 93 #else 94 static inline struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev, 95 enum msm_dsi_phy_type type, int id) { 96 return ERR_PTR(-ENODEV); 97 } 98 static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll) 99 { 100 } 101 static inline int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll, 102 struct clk **byte_clk_provider, struct clk **pixel_clk_provider) 103 { 104 return -ENODEV; 105 } 106 #endif 107 108 /* dsi host */ 109 int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host, 110 const struct mipi_dsi_msg *msg); 111 void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host, 112 const struct mipi_dsi_msg *msg); 113 int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host, 114 const struct mipi_dsi_msg *msg); 115 int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host, 116 const struct mipi_dsi_msg *msg); 117 void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host, 118 u32 iova, u32 len); 119 int msm_dsi_host_enable(struct mipi_dsi_host *host); 120 int msm_dsi_host_disable(struct mipi_dsi_host *host); 121 int msm_dsi_host_power_on(struct mipi_dsi_host *host); 122 int msm_dsi_host_power_off(struct mipi_dsi_host *host); 123 int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host, 124 struct drm_display_mode *mode); 125 struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host, 126 unsigned long *panel_flags); 127 int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer); 128 void msm_dsi_host_unregister(struct mipi_dsi_host *host); 129 int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host, 130 struct msm_dsi_pll *src_pll); 131 void msm_dsi_host_destroy(struct mipi_dsi_host *host); 132 int msm_dsi_host_modeset_init(struct mipi_dsi_host *host, 133 struct drm_device *dev); 134 int msm_dsi_host_init(struct msm_dsi *msm_dsi); 135 136 /* dsi phy */ 137 struct msm_dsi_phy; 138 struct msm_dsi_phy *msm_dsi_phy_init(struct platform_device *pdev, 139 enum msm_dsi_phy_type type, int id); 140 void msm_dsi_phy_destroy(struct msm_dsi_phy *phy); 141 int msm_dsi_phy_enable(struct msm_dsi_phy *phy, bool is_dual_panel, 142 const unsigned long bit_rate, const unsigned long esc_rate); 143 int msm_dsi_phy_disable(struct msm_dsi_phy *phy); 144 void msm_dsi_phy_get_clk_pre_post(struct msm_dsi_phy *phy, 145 u32 *clk_pre, u32 *clk_post); 146 struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy); 147 148 #endif /* __DSI_CONNECTOR_H__ */ 149 150