xref: /linux/drivers/gpu/drm/msm/dsi/dsi.h (revision 6183606da324b934166e7b47c3be6176fa86f9ff)
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);
8303436e3eSSean Paul void msm_dsi_manager_setup_encoder(int id);
84a689554bSHai Li int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
85a689554bSHai Li void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
868b03ad30SChandan Uddaraju bool msm_dsi_manager_validate_current_config(u8 id);
875e2a72d4SAbhinav Kumar void msm_dsi_manager_tpg_enable(void);
88a689554bSHai Li 
89a689554bSHai Li /* msm dsi */
906f054ec5SArchit Taneja static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
916f054ec5SArchit Taneja {
92c118e290SArchit Taneja 	return msm_dsi->panel || msm_dsi->external_bridge;
936f054ec5SArchit Taneja }
946f054ec5SArchit Taneja 
95a689554bSHai Li struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);
96a689554bSHai Li 
97a689554bSHai Li /* dsi host */
98e18177ccSSibi Sankar struct msm_dsi_host;
99a689554bSHai Li int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
100a689554bSHai Li 					const struct mipi_dsi_msg *msg);
101a689554bSHai Li void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
102a689554bSHai Li 					const struct mipi_dsi_msg *msg);
103a689554bSHai Li int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
104a689554bSHai Li 					const struct mipi_dsi_msg *msg);
105a689554bSHai Li int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
106a689554bSHai Li 					const struct mipi_dsi_msg *msg);
107a689554bSHai Li void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
1084ff9d4cbSArchit Taneja 					u32 dma_base, u32 len);
109a689554bSHai Li int msm_dsi_host_enable(struct mipi_dsi_host *host);
110a689554bSHai Li int msm_dsi_host_disable(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,
113*6183606dSDmitry Baryshkov 			bool is_bonded_dsi);
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);
120a689554bSHai Li int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer);
121a689554bSHai Li void msm_dsi_host_unregister(struct mipi_dsi_host *host);
1229d32c498SHai Li int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
1235d134596SDmitry Baryshkov 			struct msm_dsi_phy *src_phy);
12434d9545bSArchit Taneja void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
125b62aa70aSHai Li void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
126ed9976a0SChandan Uddaraju 	struct msm_dsi_phy_clk_request *clk_req,
127*6183606dSDmitry Baryshkov 	bool is_bonded_dsi);
128a689554bSHai Li void msm_dsi_host_destroy(struct mipi_dsi_host *host);
129a689554bSHai Li int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
130a689554bSHai Li 					struct drm_device *dev);
131a689554bSHai Li int msm_dsi_host_init(struct msm_dsi *msm_dsi);
132f54ca1a0SArchit Taneja int msm_dsi_runtime_suspend(struct device *dev);
133f54ca1a0SArchit Taneja int msm_dsi_runtime_resume(struct device *dev);
1346b16f05aSRob Clark int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host);
1356b16f05aSRob Clark int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host);
136c4d8cfe5SSibi Sankar int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
137c4d8cfe5SSibi Sankar int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
138c4d8cfe5SSibi Sankar void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
139c4d8cfe5SSibi Sankar void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
140c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
141c4d8cfe5SSibi Sankar int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
142c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
143c4d8cfe5SSibi Sankar void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host);
144c4d8cfe5SSibi Sankar void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host);
145c4d8cfe5SSibi Sankar int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova);
146c4d8cfe5SSibi Sankar int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova);
147c4d8cfe5SSibi Sankar int dsi_clk_init_v2(struct msm_dsi_host *msm_host);
148c4d8cfe5SSibi Sankar int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host);
149*6183606dSDmitry Baryshkov int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
150*6183606dSDmitry Baryshkov int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
151eb9d6c7eSDmitry Baryshkov void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host);
1525e2a72d4SAbhinav Kumar void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host);
1535e2a72d4SAbhinav Kumar 
154a689554bSHai Li /* dsi phy */
155a689554bSHai Li struct msm_dsi_phy;
156dceac340SHai Li struct msm_dsi_phy_shared_timings {
157dceac340SHai Li 	u32 clk_post;
158dceac340SHai Li 	u32 clk_pre;
159dceac340SHai Li 	bool clk_pre_inc_by_2;
160dceac340SHai Li };
161b62aa70aSHai Li 
162b62aa70aSHai Li struct msm_dsi_phy_clk_request {
163b62aa70aSHai Li 	unsigned long bitclk_rate;
164b62aa70aSHai Li 	unsigned long escclk_rate;
165b62aa70aSHai Li };
166b62aa70aSHai Li 
167ec31abf6SHai Li void msm_dsi_phy_driver_register(void);
168ec31abf6SHai Li void msm_dsi_phy_driver_unregister(void);
16936c5dde5SDmitry Baryshkov int msm_dsi_phy_enable(struct msm_dsi_phy *phy,
17094ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_clk_request *clk_req,
17194ad6ec9SDmitry Baryshkov 			struct msm_dsi_phy_shared_timings *shared_timings);
17229e61690SHai Li void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
17357bf4338SHai Li void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
17457bf4338SHai Li 			     enum msm_dsi_phy_usecase uc);
1755d134596SDmitry Baryshkov int msm_dsi_phy_get_clk_provider(struct msm_dsi_phy *phy,
1765d134596SDmitry Baryshkov 	struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
177aaadcbb4SDmitry Baryshkov void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy);
178aaadcbb4SDmitry Baryshkov int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy);
179d91940e2SDmitry Baryshkov void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct msm_dsi_phy *phy);
1809d32c498SHai Li 
181a689554bSHai Li #endif /* __DSI_CONNECTOR_H__ */
182a689554bSHai Li 
183