dsi.h 5.6 KB

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