dsi.h 7.4 KB

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