xref: /linux/drivers/gpu/drm/msm/dsi/dsi.h (revision 0f40ba48de3b8a4c5793013768cd62805033869c)
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>
1578f27b1cSMasahiro Yamada #include <drm/drm_panel.h>
16a689554bSHai Li 
17a689554bSHai Li #include "msm_drv.h"
189d30a4bcSAbhinav Kumar #include "disp/msm_disp_snapshot.h"
19a689554bSHai Li 
20a689554bSHai Li #define DSI_0	0
21a689554bSHai Li #define DSI_1	1
22a689554bSHai Li #define DSI_MAX	2
23a689554bSHai Li 
24dceac340SHai Li struct msm_dsi_phy_shared_timings;
25b62aa70aSHai Li struct msm_dsi_phy_clk_request;
26dceac340SHai Li 
2757bf4338SHai Li enum msm_dsi_phy_usecase {
2857bf4338SHai Li 	MSM_DSI_PHY_STANDALONE,
2957bf4338SHai Li 	MSM_DSI_PHY_MASTER,
3057bf4338SHai Li 	MSM_DSI_PHY_SLAVE,
3157bf4338SHai Li };
3257bf4338SHai Li 
33ec31abf6SHai Li #define DSI_DEV_REGULATOR_MAX	8
346e0eb52eSArchit Taneja #define DSI_BUS_CLK_MAX		4
35ec31abf6SHai Li 
36ec31abf6SHai Li /* Regulators for DSI devices */
37ec31abf6SHai Li struct dsi_reg_entry {
38ec31abf6SHai Li 	char name[32];
39ec31abf6SHai Li 	int enable_load;
40ec31abf6SHai Li 	int disable_load;
41ec31abf6SHai Li };
42ec31abf6SHai Li 
43ec31abf6SHai Li struct dsi_reg_config {
44ec31abf6SHai Li 	int num;
45ec31abf6SHai Li 	struct dsi_reg_entry regs[DSI_DEV_REGULATOR_MAX];
46ec31abf6SHai Li };
47ec31abf6SHai Li 
48a689554bSHai Li struct msm_dsi {
49a689554bSHai Li 	struct drm_device *dev;
50a689554bSHai Li 	struct platform_device *pdev;
51a689554bSHai Li 
52c118e290SArchit Taneja 	/* connector managed by us when we're connected to a drm_panel */
53a689554bSHai Li 	struct drm_connector *connector;
54c118e290SArchit Taneja 	/* internal dsi bridge attached to MDP interface */
55a689554bSHai Li 	struct drm_bridge *bridge;
56a689554bSHai Li 
57a689554bSHai Li 	struct mipi_dsi_host *host;
58a689554bSHai Li 	struct msm_dsi_phy *phy;
59c118e290SArchit Taneja 
60c118e290SArchit Taneja 	/*
61c118e290SArchit Taneja 	 * panel/external_bridge connected to dsi bridge output, only one of the
62c118e290SArchit Taneja 	 * two can be valid at a time
63c118e290SArchit Taneja 	 */
64a689554bSHai Li 	struct drm_panel *panel;
65c118e290SArchit Taneja 	struct drm_bridge *external_bridge;
669d32c498SHai Li 
67ec31abf6SHai Li 	struct device *phy_dev;
68a689554bSHai Li 	bool phy_enabled;
69a689554bSHai Li 
7097e00119SArchit Taneja 	/* the encoder we are hooked to (outside of dsi block) */
7197e00119SArchit Taneja 	struct drm_encoder *encoder;
72a689554bSHai Li 
73a689554bSHai Li 	int id;
74a689554bSHai Li };
75a689554bSHai Li 
76a689554bSHai Li /* dsi manager */
77a689554bSHai Li struct drm_bridge *msm_dsi_manager_bridge_init(u8 id);
78a689554bSHai Li void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge);
79a689554bSHai Li struct drm_connector *msm_dsi_manager_connector_init(u8 id);
80c118e290SArchit Taneja struct drm_connector *msm_dsi_manager_ext_bridge_init(u8 id);
81a689554bSHai Li int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
824ff9d4cbSArchit Taneja bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
83a689554bSHai Li int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
84a689554bSHai Li void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
855e2a72d4SAbhinav Kumar void msm_dsi_manager_tpg_enable(void);
86a689554bSHai Li 
87a689554bSHai Li /* msm dsi */
886f054ec5SArchit Taneja static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
896f054ec5SArchit Taneja {
90c118e290SArchit Taneja 	return msm_dsi->panel || msm_dsi->external_bridge;
916f054ec5SArchit Taneja }
926f054ec5SArchit Taneja 
93a689554bSHai Li struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);
94a689554bSHai Li 
95a689554bSHai Li /* dsi host */
96e18177ccSSibi Sankar struct msm_dsi_host;
97a689554bSHai Li int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
98a689554bSHai Li 					const struct mipi_dsi_msg *msg);
99a689554bSHai Li void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
100a689554bSHai Li 					const struct mipi_dsi_msg *msg);
101a689554bSHai Li int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
102a689554bSHai Li 					const struct mipi_dsi_msg *msg);
103a689554bSHai Li int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
104a689554bSHai Li 					const struct mipi_dsi_msg *msg);
105a689554bSHai Li void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
1064ff9d4cbSArchit Taneja 					u32 dma_base, u32 len);
107a689554bSHai Li int msm_dsi_host_enable(struct mipi_dsi_host *host);
108a689554bSHai Li int msm_dsi_host_disable(struct mipi_dsi_host *host);
109bf94ec09SDmitry Baryshkov void msm_dsi_host_enable_irq(struct mipi_dsi_host *host);
110bf94ec09SDmitry Baryshkov void msm_dsi_host_disable_irq(struct mipi_dsi_host *host);
111b62aa70aSHai Li int msm_dsi_host_power_on(struct mipi_dsi_host *host,
112ed9976a0SChandan Uddaraju 			struct msm_dsi_phy_shared_timings *phy_shared_timings,
113858c595aSDmitry Baryshkov 			bool is_bonded_dsi, struct msm_dsi_phy *phy);
114a689554bSHai Li int msm_dsi_host_power_off(struct mipi_dsi_host *host);
115a689554bSHai Li int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
11663f8f3baSLaurent Pinchart 				  const struct drm_display_mode *mode);
117e3a91f89SSean Paul struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host);
118e3a91f89SSean Paul unsigned long msm_dsi_host_get_mode_flags(struct mipi_dsi_host *host);
119c118e290SArchit Taneja struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host);
1208f59ee9aSRob Clark int msm_dsi_host_register(struct mipi_dsi_host *host);
121a689554bSHai Li void msm_dsi_host_unregister(struct mipi_dsi_host *host);
122a817a950SDmitry Baryshkov void msm_dsi_host_set_phy_mode(struct mipi_dsi_host *host,
123a817a950SDmitry Baryshkov 			struct msm_dsi_phy *src_phy);
1249d32c498SHai Li int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
1255d134596SDmitry Baryshkov 			struct msm_dsi_phy *src_phy);
12634d9545bSArchit Taneja void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
127b62aa70aSHai Li void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
128ed9976a0SChandan Uddaraju 	struct msm_dsi_phy_clk_request *clk_req,
1296183606dSDmitry Baryshkov 	bool is_bonded_dsi);
130a689554bSHai Li void msm_dsi_host_destroy(struct mipi_dsi_host *host);
131a689554bSHai Li int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
132a689554bSHai Li 					struct drm_device *dev);
133a689554bSHai Li int msm_dsi_host_init(struct msm_dsi *msm_dsi);
134f54ca1a0SArchit Taneja int msm_dsi_runtime_suspend(struct device *dev);
135f54ca1a0SArchit Taneja int msm_dsi_runtime_resume(struct device *dev);
1366b16f05aSRob Clark int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host);
1376b16f05aSRob Clark int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host);
138c4d8cfe5SSibi Sankar int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
139c4d8cfe5SSibi Sankar int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
140c4d8cfe5SSibi Sankar void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
141c4d8cfe5SSibi Sankar void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
142c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
143c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
144c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
145c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host);
146c4d8cfe5SSibi Sankar void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host);
147c4d8cfe5SSibi Sankar int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova);
148c4d8cfe5SSibi Sankar int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova);
149c4d8cfe5SSibi Sankar int dsi_clk_init_v2(struct msm_dsi_host *msm_host);
150c4d8cfe5SSibi Sankar int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host);
1516183606dSDmitry Baryshkov int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
1526183606dSDmitry Baryshkov int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
153eb9d6c7eSDmitry Baryshkov void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host);
1545e2a72d4SAbhinav Kumar void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host);
155*0f40ba48SVinod Koul struct msm_display_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host);
1565e2a72d4SAbhinav Kumar 
157a689554bSHai Li /* dsi phy */
158a689554bSHai Li struct msm_dsi_phy;
159dceac340SHai Li struct msm_dsi_phy_shared_timings {
160dceac340SHai Li 	u32 clk_post;
161dceac340SHai Li 	u32 clk_pre;
162dceac340SHai Li 	bool clk_pre_inc_by_2;
163dceac340SHai Li };
164b62aa70aSHai Li 
165b62aa70aSHai Li struct msm_dsi_phy_clk_request {
166b62aa70aSHai Li 	unsigned long bitclk_rate;
167b62aa70aSHai Li 	unsigned long escclk_rate;
168b62aa70aSHai Li };
169b62aa70aSHai Li 
170ec31abf6SHai Li void msm_dsi_phy_driver_register(void);
171ec31abf6SHai Li void msm_dsi_phy_driver_unregister(void);
17236c5dde5SDmitry Baryshkov int msm_dsi_phy_enable(struct msm_dsi_phy *phy,
17394ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_clk_request *clk_req,
17494ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_shared_timings *shared_timings);
17529e61690SHai Li void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
17657bf4338SHai Li void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
17757bf4338SHai Li 			     enum msm_dsi_phy_usecase uc);
178aaadcbb4SDmitry Baryshkov void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy);
179aaadcbb4SDmitry Baryshkov int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy);
180d91940e2SDmitry Baryshkov void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct msm_dsi_phy *phy);
181858c595aSDmitry Baryshkov bool msm_dsi_phy_set_continuous_clock(struct msm_dsi_phy *phy, bool enable);
1829d32c498SHai Li 
183a689554bSHai Li #endif /* __DSI_CONNECTOR_H__ */
184a689554bSHai Li 
185