dsi.h 6.1 KB

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