dsi.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_MAX
  33. };
  34. enum msm_dsi_phy_usecase {
  35. MSM_DSI_PHY_STANDALONE,
  36. MSM_DSI_PHY_MASTER,
  37. MSM_DSI_PHY_SLAVE,
  38. };
  39. #define DSI_DEV_REGULATOR_MAX 8
  40. #define DSI_BUS_CLK_MAX 4
  41. /* Regulators for DSI devices */
  42. struct dsi_reg_entry {
  43. char name[32];
  44. int enable_load;
  45. int disable_load;
  46. };
  47. struct dsi_reg_config {
  48. int num;
  49. struct dsi_reg_entry regs[DSI_DEV_REGULATOR_MAX];
  50. };
  51. struct msm_dsi {
  52. struct drm_device *dev;
  53. struct platform_device *pdev;
  54. /* connector managed by us when we're connected to a drm_panel */
  55. struct drm_connector *connector;
  56. /* internal dsi bridge attached to MDP interface */
  57. struct drm_bridge *bridge;
  58. struct mipi_dsi_host *host;
  59. struct msm_dsi_phy *phy;
  60. /*
  61. * panel/external_bridge connected to dsi bridge output, only one of the
  62. * two can be valid at a time
  63. */
  64. struct drm_panel *panel;
  65. struct drm_bridge *external_bridge;
  66. unsigned long device_flags;
  67. struct device *phy_dev;
  68. bool phy_enabled;
  69. /* the encoder we are hooked to (outside of dsi block) */
  70. struct drm_encoder *encoder;
  71. int id;
  72. };
  73. /* dsi manager */
  74. struct drm_bridge *msm_dsi_manager_bridge_init(u8 id);
  75. void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge);
  76. struct drm_connector *msm_dsi_manager_connector_init(u8 id);
  77. struct drm_connector *msm_dsi_manager_ext_bridge_init(u8 id);
  78. int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
  79. bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
  80. void msm_dsi_manager_attach_dsi_device(int id, u32 device_flags);
  81. int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
  82. void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
  83. /* msm dsi */
  84. static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
  85. {
  86. return msm_dsi->panel || msm_dsi->external_bridge;
  87. }
  88. struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);
  89. /* dsi pll */
  90. struct msm_dsi_pll;
  91. #ifdef CONFIG_DRM_MSM_DSI_PLL
  92. struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev,
  93. enum msm_dsi_phy_type type, int dsi_id);
  94. void msm_dsi_pll_destroy(struct msm_dsi_pll *pll);
  95. int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
  96. struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
  97. void msm_dsi_pll_save_state(struct msm_dsi_pll *pll);
  98. int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
  99. int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
  100. enum msm_dsi_phy_usecase uc);
  101. #else
  102. static inline struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev,
  103. enum msm_dsi_phy_type type, int id) {
  104. return ERR_PTR(-ENODEV);
  105. }
  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. /* dsi host */
  128. int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
  129. const struct mipi_dsi_msg *msg);
  130. void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
  131. const struct mipi_dsi_msg *msg);
  132. int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
  133. const struct mipi_dsi_msg *msg);
  134. int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
  135. const struct mipi_dsi_msg *msg);
  136. void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
  137. u32 dma_base, u32 len);
  138. int msm_dsi_host_enable(struct mipi_dsi_host *host);
  139. int msm_dsi_host_disable(struct mipi_dsi_host *host);
  140. int msm_dsi_host_power_on(struct mipi_dsi_host *host,
  141. struct msm_dsi_phy_shared_timings *phy_shared_timings);
  142. int msm_dsi_host_power_off(struct mipi_dsi_host *host);
  143. int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
  144. struct drm_display_mode *mode);
  145. struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host,
  146. unsigned long *panel_flags);
  147. struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host);
  148. int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer);
  149. void msm_dsi_host_unregister(struct mipi_dsi_host *host);
  150. int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
  151. struct msm_dsi_pll *src_pll);
  152. void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
  153. void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
  154. struct msm_dsi_phy_clk_request *clk_req);
  155. void msm_dsi_host_destroy(struct mipi_dsi_host *host);
  156. int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
  157. struct drm_device *dev);
  158. int msm_dsi_host_init(struct msm_dsi *msm_dsi);
  159. int msm_dsi_runtime_suspend(struct device *dev);
  160. int msm_dsi_runtime_resume(struct device *dev);
  161. /* dsi phy */
  162. struct msm_dsi_phy;
  163. struct msm_dsi_phy_shared_timings {
  164. u32 clk_post;
  165. u32 clk_pre;
  166. bool clk_pre_inc_by_2;
  167. };
  168. struct msm_dsi_phy_clk_request {
  169. unsigned long bitclk_rate;
  170. unsigned long escclk_rate;
  171. };
  172. void msm_dsi_phy_driver_register(void);
  173. void msm_dsi_phy_driver_unregister(void);
  174. int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
  175. struct msm_dsi_phy_clk_request *clk_req);
  176. void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
  177. void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy *phy,
  178. struct msm_dsi_phy_shared_timings *shared_timing);
  179. struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy);
  180. void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
  181. enum msm_dsi_phy_usecase uc);
  182. #endif /* __DSI_CONNECTOR_H__ */