xref: /linux/drivers/gpu/drm/msm/dsi/dsi.h (revision 5f403fd7d5c2a33be51b7f4cd4d0219e314d90f1)
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 
38c118e290SArchit Taneja 	/* internal dsi bridge attached to MDP interface */
39a689554bSHai Li 	struct drm_bridge *bridge;
40a689554bSHai Li 
41a689554bSHai Li 	struct mipi_dsi_host *host;
42a689554bSHai Li 	struct msm_dsi_phy *phy;
43c118e290SArchit Taneja 
44c118e290SArchit Taneja 	/*
45007ac026SDmitry Baryshkov 	 * external_bridge connected to dsi bridge output
46c118e290SArchit Taneja 	 */
47c118e290SArchit Taneja 	struct drm_bridge *external_bridge;
489d32c498SHai Li 
49ec31abf6SHai Li 	struct device *phy_dev;
50a689554bSHai Li 	bool phy_enabled;
51a689554bSHai Li 
5297e00119SArchit Taneja 	/* the encoder we are hooked to (outside of dsi block) */
5397e00119SArchit Taneja 	struct drm_encoder *encoder;
54a689554bSHai Li 
55a689554bSHai Li 	int id;
56a689554bSHai Li };
57a689554bSHai Li 
58a689554bSHai Li /* dsi manager */
59*5f403fd7SDmitry Baryshkov int msm_dsi_manager_bridge_init(struct msm_dsi *msm_dsi);
60007ac026SDmitry Baryshkov int msm_dsi_manager_ext_bridge_init(u8 id);
61a689554bSHai Li int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
624ff9d4cbSArchit Taneja bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
63a689554bSHai Li int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
64a689554bSHai Li void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
655e2a72d4SAbhinav Kumar void msm_dsi_manager_tpg_enable(void);
66a689554bSHai Li 
67a689554bSHai Li /* msm dsi */
686f054ec5SArchit Taneja static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
696f054ec5SArchit Taneja {
70007ac026SDmitry Baryshkov 	return msm_dsi->external_bridge;
716f054ec5SArchit Taneja }
726f054ec5SArchit Taneja 
73a689554bSHai Li /* dsi host */
74e18177ccSSibi Sankar struct msm_dsi_host;
75a689554bSHai Li int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
76a689554bSHai Li 					const struct mipi_dsi_msg *msg);
77a689554bSHai Li void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
78a689554bSHai Li 					const struct mipi_dsi_msg *msg);
79a689554bSHai Li int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
80a689554bSHai Li 					const struct mipi_dsi_msg *msg);
81a689554bSHai Li int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
82a689554bSHai Li 					const struct mipi_dsi_msg *msg);
83a689554bSHai Li void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
844ff9d4cbSArchit Taneja 					u32 dma_base, u32 len);
85a689554bSHai Li int msm_dsi_host_enable(struct mipi_dsi_host *host);
86a689554bSHai Li int msm_dsi_host_disable(struct mipi_dsi_host *host);
87bf94ec09SDmitry Baryshkov void msm_dsi_host_enable_irq(struct mipi_dsi_host *host);
88bf94ec09SDmitry Baryshkov void msm_dsi_host_disable_irq(struct mipi_dsi_host *host);
89b62aa70aSHai Li int msm_dsi_host_power_on(struct mipi_dsi_host *host,
90ed9976a0SChandan Uddaraju 			struct msm_dsi_phy_shared_timings *phy_shared_timings,
91858c595aSDmitry Baryshkov 			bool is_bonded_dsi, struct msm_dsi_phy *phy);
92a689554bSHai Li int msm_dsi_host_power_off(struct mipi_dsi_host *host);
93a689554bSHai Li int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
9463f8f3baSLaurent Pinchart 				  const struct drm_display_mode *mode);
9589f1bfc4SVinod Koul enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
9689f1bfc4SVinod Koul 					    const struct drm_display_mode *mode);
97e3a91f89SSean Paul unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host);
988f59ee9aSRob Clark int msm_dsi_host_register(struct mipi_dsi_host *host);
99a689554bSHai Li void msm_dsi_host_unregister(struct mipi_dsi_host *host);
100a817a950SDmitry Baryshkov void msm_dsi_host_set_phy_mode(struct mipi_dsi_host *host,
101a817a950SDmitry Baryshkov 			struct msm_dsi_phy *src_phy);
1029d32c498SHai Li int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
1035d134596SDmitry Baryshkov 			struct msm_dsi_phy *src_phy);
10434d9545bSArchit Taneja void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
105b62aa70aSHai Li void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
106ed9976a0SChandan Uddaraju 	struct msm_dsi_phy_clk_request *clk_req,
1076183606dSDmitry Baryshkov 	bool is_bonded_dsi);
108a689554bSHai Li void msm_dsi_host_destroy(struct mipi_dsi_host *host);
109a689554bSHai Li int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
110a689554bSHai Li 					struct drm_device *dev);
111a689554bSHai Li int msm_dsi_host_init(struct msm_dsi *msm_dsi);
112f54ca1a0SArchit Taneja int msm_dsi_runtime_suspend(struct device *dev);
113f54ca1a0SArchit Taneja int msm_dsi_runtime_resume(struct device *dev);
1146b16f05aSRob Clark int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host);
1156b16f05aSRob Clark int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host);
116c4d8cfe5SSibi Sankar int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
117c4d8cfe5SSibi Sankar int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
118c4d8cfe5SSibi Sankar void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
119c4d8cfe5SSibi Sankar void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
12003f7b782SAbhinav Kumar unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
12103f7b782SAbhinav Kumar 				    const struct drm_display_mode *mode);
122c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
123c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
124c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
125c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host);
126c4d8cfe5SSibi Sankar void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host);
127c4d8cfe5SSibi Sankar int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova);
128c4d8cfe5SSibi Sankar int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova);
129c4d8cfe5SSibi Sankar int dsi_clk_init_v2(struct msm_dsi_host *msm_host);
130c4d8cfe5SSibi Sankar int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host);
1316183606dSDmitry Baryshkov int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
1326183606dSDmitry Baryshkov int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
133eb9d6c7eSDmitry Baryshkov void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host);
1345e2a72d4SAbhinav Kumar void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host);
1354b2b1b36SDmitry Baryshkov struct drm_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host);
136efcbd6f9SJessica Zhang bool msm_dsi_host_is_wide_bus_enabled(struct mipi_dsi_host *host);
1375e2a72d4SAbhinav Kumar 
138a689554bSHai Li /* dsi phy */
139a689554bSHai Li struct msm_dsi_phy;
140dceac340SHai Li struct msm_dsi_phy_shared_timings {
141dceac340SHai Li 	u32 clk_post;
142dceac340SHai Li 	u32 clk_pre;
143dceac340SHai Li 	bool clk_pre_inc_by_2;
1441d5e01dfSDmitry Baryshkov 	bool byte_intf_clk_div_2;
145dceac340SHai Li };
146b62aa70aSHai Li 
147b62aa70aSHai Li struct msm_dsi_phy_clk_request {
148b62aa70aSHai Li 	unsigned long bitclk_rate;
149b62aa70aSHai Li 	unsigned long escclk_rate;
150b62aa70aSHai Li };
151b62aa70aSHai Li 
152ec31abf6SHai Li void msm_dsi_phy_driver_register(void);
153ec31abf6SHai Li void msm_dsi_phy_driver_unregister(void);
15436c5dde5SDmitry Baryshkov int msm_dsi_phy_enable(struct msm_dsi_phy *phy,
15594ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_clk_request *clk_req,
15694ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_shared_timings *shared_timings);
15729e61690SHai Li void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
15857bf4338SHai Li void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
15957bf4338SHai Li 			     enum msm_dsi_phy_usecase uc);
160aaadcbb4SDmitry Baryshkov void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy);
161aaadcbb4SDmitry Baryshkov int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy);
162d91940e2SDmitry Baryshkov void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct msm_dsi_phy *phy);
163858c595aSDmitry Baryshkov bool msm_dsi_phy_set_continuous_clock(struct msm_dsi_phy *phy, bool enable);
1649d32c498SHai Li 
165a689554bSHai Li #endif /* __DSI_CONNECTOR_H__ */
166a689554bSHai Li 
167