xref: /linux/drivers/gpu/drm/msm/dsi/dsi.h (revision 3f41368fbfe1b3d5922d317fe1a0a0cab6846802)
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 
16 #include "msm_drv.h"
17 #include "disp/msm_disp_snapshot.h"
18 
19 #define DSI_0	0
20 #define DSI_1	1
21 #define DSI_MAX	2
22 
23 struct msm_dsi_phy_shared_timings;
24 struct msm_dsi_phy_clk_request;
25 
26 enum msm_dsi_phy_usecase {
27 	MSM_DSI_PHY_STANDALONE,
28 	MSM_DSI_PHY_MASTER,
29 	MSM_DSI_PHY_SLAVE,
30 };
31 
32 #define DSI_BUS_CLK_MAX		4
33 
34 struct msm_dsi {
35 	struct drm_device *dev;
36 	struct platform_device *pdev;
37 
38 	struct mipi_dsi_host *host;
39 	struct msm_dsi_phy *phy;
40 
41 	struct drm_bridge *next_bridge;
42 
43 	struct device *phy_dev;
44 	bool phy_enabled;
45 
46 	int id;
47 };
48 
49 /* dsi manager */
50 int msm_dsi_manager_connector_init(struct msm_dsi *msm_dsi,
51 				   struct drm_encoder *encoder);
52 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
53 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
54 int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
55 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
56 void msm_dsi_manager_tpg_enable(void);
57 
58 /* dsi host */
59 struct msm_dsi_host;
60 int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
61 					const struct mipi_dsi_msg *msg);
62 void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
63 					const struct mipi_dsi_msg *msg);
64 int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
65 					const struct mipi_dsi_msg *msg);
66 int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
67 					const struct mipi_dsi_msg *msg);
68 void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
69 					u32 dma_base, u32 len);
70 int msm_dsi_host_enable(struct mipi_dsi_host *host);
71 int msm_dsi_host_disable(struct mipi_dsi_host *host);
72 void msm_dsi_host_enable_irq(struct mipi_dsi_host *host);
73 void msm_dsi_host_disable_irq(struct mipi_dsi_host *host);
74 int msm_dsi_host_power_on(struct mipi_dsi_host *host,
75 			struct msm_dsi_phy_shared_timings *phy_shared_timings,
76 			bool is_bonded_dsi, struct msm_dsi_phy *phy);
77 int msm_dsi_host_power_off(struct mipi_dsi_host *host);
78 int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
79 				  const struct drm_display_mode *mode);
80 enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
81 					    const struct drm_display_mode *mode);
82 unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host);
83 int msm_dsi_host_register(struct mipi_dsi_host *host);
84 void msm_dsi_host_unregister(struct mipi_dsi_host *host);
85 void msm_dsi_host_set_phy_mode(struct mipi_dsi_host *host,
86 			struct msm_dsi_phy *src_phy);
87 int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
88 			struct msm_dsi_phy *src_phy);
89 void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
90 void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
91 	struct msm_dsi_phy_clk_request *clk_req,
92 	bool is_bonded_dsi);
93 void msm_dsi_host_destroy(struct mipi_dsi_host *host);
94 int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
95 					struct drm_device *dev);
96 int msm_dsi_host_init(struct msm_dsi *msm_dsi);
97 int msm_dsi_runtime_suspend(struct device *dev);
98 int msm_dsi_runtime_resume(struct device *dev);
99 int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host);
100 int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host);
101 int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
102 int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
103 void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
104 void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
105 unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
106 				    const struct drm_display_mode *mode);
107 int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
108 int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
109 void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
110 void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host);
111 void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host);
112 void msm_dsi_tx_buf_free(struct mipi_dsi_host *mipi_host);
113 int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova);
114 int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova);
115 int dsi_clk_init_v2(struct msm_dsi_host *msm_host);
116 int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host);
117 int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
118 int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
119 void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host);
120 void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host);
121 struct drm_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host);
122 bool msm_dsi_host_is_wide_bus_enabled(struct mipi_dsi_host *host);
123 
124 /* dsi phy */
125 struct msm_dsi_phy;
126 struct msm_dsi_phy_shared_timings {
127 	u32 clk_post;
128 	u32 clk_pre;
129 	bool clk_pre_inc_by_2;
130 	bool byte_intf_clk_div_2;
131 };
132 
133 struct msm_dsi_phy_clk_request {
134 	unsigned long bitclk_rate;
135 	unsigned long escclk_rate;
136 };
137 
138 void msm_dsi_phy_driver_register(void);
139 void msm_dsi_phy_driver_unregister(void);
140 int msm_dsi_phy_enable(struct msm_dsi_phy *phy,
141 			struct msm_dsi_phy_clk_request *clk_req,
142 			struct msm_dsi_phy_shared_timings *shared_timings);
143 void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
144 void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
145 			     enum msm_dsi_phy_usecase uc);
146 void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy);
147 int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy);
148 void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct msm_dsi_phy *phy);
149 bool msm_dsi_phy_set_continuous_clock(struct msm_dsi_phy *phy, bool enable);
150 
151 #endif /* __DSI_CONNECTOR_H__ */
152 
153