xref: /linux/drivers/gpu/drm/msm/dsi/dsi.h (revision ec97f371895f83fb0c123187d26d19bdb927621f)
197fb5e8dSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2a689554bSHai Li /*
3a689554bSHai Li  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
4a689554bSHai Li  */
5a689554bSHai Li 
6a689554bSHai Li #ifndef __DSI_CONNECTOR_H__
7a689554bSHai Li #define __DSI_CONNECTOR_H__
8a689554bSHai Li 
9ec31abf6SHai Li #include <linux/of_platform.h>
10a689554bSHai Li #include <linux/platform_device.h>
11a689554bSHai Li 
12ee68c743SBoris Brezillon #include <drm/drm_bridge.h>
1378f27b1cSMasahiro Yamada #include <drm/drm_crtc.h>
1478f27b1cSMasahiro Yamada #include <drm/drm_mipi_dsi.h>
15a689554bSHai Li 
16a689554bSHai Li #include "msm_drv.h"
179d30a4bcSAbhinav Kumar #include "disp/msm_disp_snapshot.h"
18a689554bSHai Li 
19a689554bSHai Li #define DSI_0	0
20a689554bSHai Li #define DSI_1	1
21a689554bSHai Li #define DSI_MAX	2
22a689554bSHai Li 
23dceac340SHai Li struct msm_dsi_phy_shared_timings;
24b62aa70aSHai Li struct msm_dsi_phy_clk_request;
25dceac340SHai Li 
2657bf4338SHai Li enum msm_dsi_phy_usecase {
2757bf4338SHai Li 	MSM_DSI_PHY_STANDALONE,
2857bf4338SHai Li 	MSM_DSI_PHY_MASTER,
2957bf4338SHai Li 	MSM_DSI_PHY_SLAVE,
3057bf4338SHai Li };
3157bf4338SHai Li 
326e0eb52eSArchit Taneja #define DSI_BUS_CLK_MAX		4
33ec31abf6SHai Li 
34a689554bSHai Li struct msm_dsi {
35a689554bSHai Li 	struct drm_device *dev;
36a689554bSHai Li 	struct platform_device *pdev;
37a689554bSHai Li 
38a689554bSHai Li 	struct mipi_dsi_host *host;
39a689554bSHai Li 	struct msm_dsi_phy *phy;
40c118e290SArchit Taneja 
41c118e290SArchit Taneja 	/*
42007ac026SDmitry Baryshkov 	 * external_bridge connected to dsi bridge output
43c118e290SArchit Taneja 	 */
44c118e290SArchit Taneja 	struct drm_bridge *external_bridge;
459d32c498SHai Li 
46ec31abf6SHai Li 	struct device *phy_dev;
47a689554bSHai Li 	bool phy_enabled;
48a689554bSHai Li 
4997e00119SArchit Taneja 	/* the encoder we are hooked to (outside of dsi block) */
5097e00119SArchit Taneja 	struct drm_encoder *encoder;
51a689554bSHai Li 
52a689554bSHai Li 	int id;
53a689554bSHai Li };
54a689554bSHai Li 
55a689554bSHai Li /* dsi manager */
56*ec97f371SDmitry Baryshkov struct drm_bridge *msm_dsi_manager_bridge_init(struct msm_dsi *msm_dsi);
57*ec97f371SDmitry Baryshkov int msm_dsi_manager_ext_bridge_init(u8 id, struct drm_bridge *int_bridge);
58a689554bSHai Li int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
594ff9d4cbSArchit Taneja bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
60a689554bSHai Li int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
61a689554bSHai Li void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
625e2a72d4SAbhinav Kumar void msm_dsi_manager_tpg_enable(void);
63a689554bSHai Li 
64a689554bSHai Li /* msm dsi */
656f054ec5SArchit Taneja static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
666f054ec5SArchit Taneja {
67007ac026SDmitry Baryshkov 	return msm_dsi->external_bridge;
686f054ec5SArchit Taneja }
696f054ec5SArchit Taneja 
70a689554bSHai Li /* dsi host */
71e18177ccSSibi Sankar struct msm_dsi_host;
72a689554bSHai Li int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
73a689554bSHai Li 					const struct mipi_dsi_msg *msg);
74a689554bSHai Li void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
75a689554bSHai Li 					const struct mipi_dsi_msg *msg);
76a689554bSHai Li int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
77a689554bSHai Li 					const struct mipi_dsi_msg *msg);
78a689554bSHai Li int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
79a689554bSHai Li 					const struct mipi_dsi_msg *msg);
80a689554bSHai Li void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
814ff9d4cbSArchit Taneja 					u32 dma_base, u32 len);
82a689554bSHai Li int msm_dsi_host_enable(struct mipi_dsi_host *host);
83a689554bSHai Li int msm_dsi_host_disable(struct mipi_dsi_host *host);
84bf94ec09SDmitry Baryshkov void msm_dsi_host_enable_irq(struct mipi_dsi_host *host);
85bf94ec09SDmitry Baryshkov void msm_dsi_host_disable_irq(struct mipi_dsi_host *host);
86b62aa70aSHai Li int msm_dsi_host_power_on(struct mipi_dsi_host *host,
87ed9976a0SChandan Uddaraju 			struct msm_dsi_phy_shared_timings *phy_shared_timings,
88858c595aSDmitry Baryshkov 			bool is_bonded_dsi, struct msm_dsi_phy *phy);
89a689554bSHai Li int msm_dsi_host_power_off(struct mipi_dsi_host *host);
90a689554bSHai Li int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
9163f8f3baSLaurent Pinchart 				  const struct drm_display_mode *mode);
9289f1bfc4SVinod Koul enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
9389f1bfc4SVinod Koul 					    const struct drm_display_mode *mode);
94e3a91f89SSean Paul unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host);
958f59ee9aSRob Clark int msm_dsi_host_register(struct mipi_dsi_host *host);
96a689554bSHai Li void msm_dsi_host_unregister(struct mipi_dsi_host *host);
97a817a950SDmitry Baryshkov void msm_dsi_host_set_phy_mode(struct mipi_dsi_host *host,
98a817a950SDmitry Baryshkov 			struct msm_dsi_phy *src_phy);
999d32c498SHai Li int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
1005d134596SDmitry Baryshkov 			struct msm_dsi_phy *src_phy);
10134d9545bSArchit Taneja void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
102b62aa70aSHai Li void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
103ed9976a0SChandan Uddaraju 	struct msm_dsi_phy_clk_request *clk_req,
1046183606dSDmitry Baryshkov 	bool is_bonded_dsi);
105a689554bSHai Li void msm_dsi_host_destroy(struct mipi_dsi_host *host);
106a689554bSHai Li int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
107a689554bSHai Li 					struct drm_device *dev);
108a689554bSHai Li int msm_dsi_host_init(struct msm_dsi *msm_dsi);
109f54ca1a0SArchit Taneja int msm_dsi_runtime_suspend(struct device *dev);
110f54ca1a0SArchit Taneja int msm_dsi_runtime_resume(struct device *dev);
1116b16f05aSRob Clark int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host);
1126b16f05aSRob Clark int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host);
113c4d8cfe5SSibi Sankar int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
114c4d8cfe5SSibi Sankar int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
115c4d8cfe5SSibi Sankar void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
116c4d8cfe5SSibi Sankar void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
11703f7b782SAbhinav Kumar unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
11803f7b782SAbhinav Kumar 				    const struct drm_display_mode *mode);
119c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
120c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
121c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
122c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host);
123c4d8cfe5SSibi Sankar void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host);
1245e05be78SDmitry Baryshkov void msm_dsi_tx_buf_free(struct mipi_dsi_host *mipi_host);
125c4d8cfe5SSibi Sankar int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova);
126c4d8cfe5SSibi Sankar int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova);
127c4d8cfe5SSibi Sankar int dsi_clk_init_v2(struct msm_dsi_host *msm_host);
128c4d8cfe5SSibi Sankar int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host);
1296183606dSDmitry Baryshkov int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
1306183606dSDmitry Baryshkov int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
131eb9d6c7eSDmitry Baryshkov void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host);
1325e2a72d4SAbhinav Kumar void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host);
1334b2b1b36SDmitry Baryshkov struct drm_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host);
134efcbd6f9SJessica Zhang bool msm_dsi_host_is_wide_bus_enabled(struct mipi_dsi_host *host);
1355e2a72d4SAbhinav Kumar 
136a689554bSHai Li /* dsi phy */
137a689554bSHai Li struct msm_dsi_phy;
138dceac340SHai Li struct msm_dsi_phy_shared_timings {
139dceac340SHai Li 	u32 clk_post;
140dceac340SHai Li 	u32 clk_pre;
141dceac340SHai Li 	bool clk_pre_inc_by_2;
1421d5e01dfSDmitry Baryshkov 	bool byte_intf_clk_div_2;
143dceac340SHai Li };
144b62aa70aSHai Li 
145b62aa70aSHai Li struct msm_dsi_phy_clk_request {
146b62aa70aSHai Li 	unsigned long bitclk_rate;
147b62aa70aSHai Li 	unsigned long escclk_rate;
148b62aa70aSHai Li };
149b62aa70aSHai Li 
150ec31abf6SHai Li void msm_dsi_phy_driver_register(void);
151ec31abf6SHai Li void msm_dsi_phy_driver_unregister(void);
15236c5dde5SDmitry Baryshkov int msm_dsi_phy_enable(struct msm_dsi_phy *phy,
15394ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_clk_request *clk_req,
15494ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_shared_timings *shared_timings);
15529e61690SHai Li void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
15657bf4338SHai Li void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
15757bf4338SHai Li 			     enum msm_dsi_phy_usecase uc);
158aaadcbb4SDmitry Baryshkov void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy);
159aaadcbb4SDmitry Baryshkov int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy);
160d91940e2SDmitry Baryshkov void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct msm_dsi_phy *phy);
161858c595aSDmitry Baryshkov bool msm_dsi_phy_set_continuous_clock(struct msm_dsi_phy *phy, bool enable);
1629d32c498SHai Li 
163a689554bSHai Li #endif /* __DSI_CONNECTOR_H__ */
164a689554bSHai Li 
165