dsi.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. /* msm dsi */
  85. static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
  86. {
  87. return msm_dsi->panel || msm_dsi->external_bridge;
  88. }
  89. struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);
  90. /* dsi pll */
  91. struct msm_dsi_pll;
  92. #ifdef CONFIG_DRM_MSM_DSI_PLL
  93. struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev,
  94. enum msm_dsi_phy_type type, int dsi_id);
  95. void msm_dsi_pll_destroy(struct msm_dsi_pll *pll);
  96. int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
  97. struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
  98. void msm_dsi_pll_save_state(struct msm_dsi_pll *pll);
  99. int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
  100. int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
  101. enum msm_dsi_phy_usecase uc);
  102. #else
  103. static inline struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev,
  104. enum msm_dsi_phy_type type, int id) {
  105. return ERR_PTR(-ENODEV);
  106. }
  107. static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll)
  108. {
  109. }
  110. static inline int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
  111. struct clk **byte_clk_provider, struct clk **pixel_clk_provider)
  112. {
  113. return -ENODEV;
  114. }
  115. static inline void msm_dsi_pll_save_state(struct msm_dsi_pll *pll)
  116. {
  117. }
  118. static inline int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll)
  119. {
  120. return 0;
  121. }
  122. static inline int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
  123. enum msm_dsi_phy_usecase uc)
  124. {
  125. return -ENODEV;
  126. }
  127. #endif
  128. /* dsi host */
  129. int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
  130. const struct mipi_dsi_msg *msg);
  131. void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
  132. const struct mipi_dsi_msg *msg);
  133. int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
  134. const struct mipi_dsi_msg *msg);
  135. int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
  136. const struct mipi_dsi_msg *msg);
  137. void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
  138. u32 dma_base, u32 len);
  139. int msm_dsi_host_enable(struct mipi_dsi_host *host);
  140. int msm_dsi_host_disable(struct mipi_dsi_host *host);
  141. int msm_dsi_host_power_on(struct mipi_dsi_host *host,
  142. struct msm_dsi_phy_shared_timings *phy_shared_timings);
  143. int msm_dsi_host_power_off(struct mipi_dsi_host *host);
  144. int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
  145. struct drm_display_mode *mode);
  146. struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host,
  147. unsigned long *panel_flags);
  148. struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host);
  149. int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer);
  150. void msm_dsi_host_unregister(struct mipi_dsi_host *host);
  151. int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
  152. struct msm_dsi_pll *src_pll);
  153. void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
  154. void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
  155. struct msm_dsi_phy_clk_request *clk_req);
  156. void msm_dsi_host_destroy(struct mipi_dsi_host *host);
  157. int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
  158. struct drm_device *dev);
  159. int msm_dsi_host_init(struct msm_dsi *msm_dsi);
  160. int msm_dsi_runtime_suspend(struct device *dev);
  161. int msm_dsi_runtime_resume(struct device *dev);
  162. /* dsi phy */
  163. struct msm_dsi_phy;
  164. struct msm_dsi_phy_shared_timings {
  165. u32 clk_post;
  166. u32 clk_pre;
  167. bool clk_pre_inc_by_2;
  168. };
  169. struct msm_dsi_phy_clk_request {
  170. unsigned long bitclk_rate;
  171. unsigned long escclk_rate;
  172. };
  173. void msm_dsi_phy_driver_register(void);
  174. void msm_dsi_phy_driver_unregister(void);
  175. int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
  176. struct msm_dsi_phy_clk_request *clk_req);
  177. void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
  178. void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy *phy,
  179. struct msm_dsi_phy_shared_timings *shared_timing);
  180. struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy);
  181. void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
  182. enum msm_dsi_phy_usecase uc);
  183. #endif /* __DSI_CONNECTOR_H__ */