xref: /linux/drivers/gpu/drm/msm/dsi/dsi.h (revision d8810a66924482fc3977cebe3404629ad2647743)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
4  */
5 
6 #ifndef __DSI_CONNECTOR_H__
7 #define __DSI_CONNECTOR_H__
8 
9 #include <linux/of_platform.h>
10 #include <linux/platform_device.h>
11 
12 #include <drm/drm_bridge.h>
13 #include <drm/drm_crtc.h>
14 #include <drm/drm_mipi_dsi.h>
15 #include <drm/drm_panel.h>
16 
17 #include "msm_drv.h"
18 #include "disp/msm_disp_snapshot.h"
19 
20 #define DSI_0	0
21 #define DSI_1	1
22 #define DSI_MAX	2
23 
24 struct msm_dsi_phy_shared_timings;
25 struct msm_dsi_phy_clk_request;
26 
27 enum msm_dsi_phy_usecase {
28 	MSM_DSI_PHY_STANDALONE,
29 	MSM_DSI_PHY_MASTER,
30 	MSM_DSI_PHY_SLAVE,
31 };
32 
33 #define DSI_BUS_CLK_MAX		4
34 
35 struct msm_dsi {
36 	struct drm_device *dev;
37 	struct platform_device *pdev;
38 
39 	/* connector managed by us when we're connected to a drm_panel */
40 	struct drm_connector *connector;
41 	/* internal dsi bridge attached to MDP interface */
42 	struct drm_bridge *bridge;
43 
44 	struct mipi_dsi_host *host;
45 	struct msm_dsi_phy *phy;
46 
47 	/*
48 	 * panel/external_bridge connected to dsi bridge output, only one of the
49 	 * two can be valid at a time
50 	 */
51 	struct drm_panel *panel;
52 	struct drm_bridge *external_bridge;
53 
54 	struct device *phy_dev;
55 	bool phy_enabled;
56 
57 	/* the encoder we are hooked to (outside of dsi block) */
58 	struct drm_encoder *encoder;
59 
60 	int id;
61 };
62 
63 /* dsi manager */
64 struct drm_bridge *msm_dsi_manager_bridge_init(u8 id);
65 void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge);
66 struct drm_connector *msm_dsi_manager_connector_init(u8 id);
67 struct drm_connector *msm_dsi_manager_ext_bridge_init(u8 id);
68 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
69 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
70 int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
71 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
72 void msm_dsi_manager_tpg_enable(void);
73 
74 /* msm dsi */
75 static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
76 {
77 	return msm_dsi->panel || msm_dsi->external_bridge;
78 }
79 
80 struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);
81 
82 /* dsi host */
83 struct msm_dsi_host;
84 int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
85 					const struct mipi_dsi_msg *msg);
86 void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
87 					const struct mipi_dsi_msg *msg);
88 int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
89 					const struct mipi_dsi_msg *msg);
90 int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
91 					const struct mipi_dsi_msg *msg);
92 void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
93 					u32 dma_base, u32 len);
94 int msm_dsi_host_enable(struct mipi_dsi_host *host);
95 int msm_dsi_host_disable(struct mipi_dsi_host *host);
96 void msm_dsi_host_enable_irq(struct mipi_dsi_host *host);
97 void msm_dsi_host_disable_irq(struct mipi_dsi_host *host);
98 int msm_dsi_host_power_on(struct mipi_dsi_host *host,
99 			struct msm_dsi_phy_shared_timings *phy_shared_timings,
100 			bool is_bonded_dsi, struct msm_dsi_phy *phy);
101 int msm_dsi_host_power_off(struct mipi_dsi_host *host);
102 int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
103 				  const struct drm_display_mode *mode);
104 enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
105 					    const struct drm_display_mode *mode);
106 struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host);
107 unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host);
108 struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host);
109 int msm_dsi_host_register(struct mipi_dsi_host *host);
110 void msm_dsi_host_unregister(struct mipi_dsi_host *host);
111 void msm_dsi_host_set_phy_mode(struct mipi_dsi_host *host,
112 			struct msm_dsi_phy *src_phy);
113 int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
114 			struct msm_dsi_phy *src_phy);
115 void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
116 void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
117 	struct msm_dsi_phy_clk_request *clk_req,
118 	bool is_bonded_dsi);
119 void msm_dsi_host_destroy(struct mipi_dsi_host *host);
120 int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
121 					struct drm_device *dev);
122 int msm_dsi_host_init(struct msm_dsi *msm_dsi);
123 int msm_dsi_runtime_suspend(struct device *dev);
124 int msm_dsi_runtime_resume(struct device *dev);
125 int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host);
126 int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host);
127 int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
128 int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
129 void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
130 void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
131 int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
132 int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
133 void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
134 void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host);
135 void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host);
136 int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova);
137 int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova);
138 int dsi_clk_init_v2(struct msm_dsi_host *msm_host);
139 int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host);
140 int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
141 int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
142 void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host);
143 void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host);
144 struct drm_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host);
145 
146 /* dsi phy */
147 struct msm_dsi_phy;
148 struct msm_dsi_phy_shared_timings {
149 	u32 clk_post;
150 	u32 clk_pre;
151 	bool clk_pre_inc_by_2;
152 };
153 
154 struct msm_dsi_phy_clk_request {
155 	unsigned long bitclk_rate;
156 	unsigned long escclk_rate;
157 };
158 
159 void msm_dsi_phy_driver_register(void);
160 void msm_dsi_phy_driver_unregister(void);
161 int msm_dsi_phy_enable(struct msm_dsi_phy *phy,
162 			struct msm_dsi_phy_clk_request *clk_req,
163 			struct msm_dsi_phy_shared_timings *shared_timings);
164 void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
165 void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
166 			     enum msm_dsi_phy_usecase uc);
167 void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy);
168 int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy);
169 void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct msm_dsi_phy *phy);
170 bool msm_dsi_phy_set_continuous_clock(struct msm_dsi_phy *phy, bool enable);
171 
172 #endif /* __DSI_CONNECTOR_H__ */
173 
174