dsi.h 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __DSI_CONNECTOR_H__
#define __DSI_CONNECTOR_H__

17
#include <linux/of_platform.h>
18 19
#include <linux/platform_device.h>

20 21 22
#include <drm/drm_crtc.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_panel.h>
23 24 25 26 27 28 29

#include "msm_drv.h"

#define DSI_0	0
#define DSI_1	1
#define DSI_MAX	2

30
struct msm_dsi_phy_shared_timings;
31
struct msm_dsi_phy_clk_request;
32

33 34 35
enum msm_dsi_phy_type {
	MSM_DSI_PHY_28NM_HPM,
	MSM_DSI_PHY_28NM_LP,
H
Hai Li 已提交
36
	MSM_DSI_PHY_20NM,
37
	MSM_DSI_PHY_28NM_8960,
38
	MSM_DSI_PHY_14NM,
39
	MSM_DSI_PHY_10NM,
40 41 42
	MSM_DSI_PHY_MAX
};

H
Hai Li 已提交
43 44 45 46 47 48
enum msm_dsi_phy_usecase {
	MSM_DSI_PHY_STANDALONE,
	MSM_DSI_PHY_MASTER,
	MSM_DSI_PHY_SLAVE,
};

49
#define DSI_DEV_REGULATOR_MAX	8
50
#define DSI_BUS_CLK_MAX		4
51 52 53 54 55 56 57 58 59 60 61 62 63

/* Regulators for DSI devices */
struct dsi_reg_entry {
	char name[32];
	int enable_load;
	int disable_load;
};

struct dsi_reg_config {
	int num;
	struct dsi_reg_entry regs[DSI_DEV_REGULATOR_MAX];
};

64 65 66 67
struct msm_dsi {
	struct drm_device *dev;
	struct platform_device *pdev;

68
	/* connector managed by us when we're connected to a drm_panel */
69
	struct drm_connector *connector;
70
	/* internal dsi bridge attached to MDP interface */
71 72 73 74
	struct drm_bridge *bridge;

	struct mipi_dsi_host *host;
	struct msm_dsi_phy *phy;
75 76 77 78 79

	/*
	 * panel/external_bridge connected to dsi bridge output, only one of the
	 * two can be valid at a time
	 */
80
	struct drm_panel *panel;
81
	struct drm_bridge *external_bridge;
82
	unsigned long device_flags;
83

84
	struct device *phy_dev;
85 86
	bool phy_enabled;

87 88
	/* the encoder we are hooked to (outside of dsi block) */
	struct drm_encoder *encoder;
89 90 91 92 93 94 95 96

	int id;
};

/* dsi manager */
struct drm_bridge *msm_dsi_manager_bridge_init(u8 id);
void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge);
struct drm_connector *msm_dsi_manager_connector_init(u8 id);
97
struct drm_connector *msm_dsi_manager_ext_bridge_init(u8 id);
98
int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
99
bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
100
void msm_dsi_manager_attach_dsi_device(int id, u32 device_flags);
101 102
int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
103
bool msm_dsi_manager_validate_current_config(u8 id);
104 105

/* msm dsi */
106 107
static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
{
108
	return msm_dsi->panel || msm_dsi->external_bridge;
109 110
}

111 112
struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);

113 114 115 116 117 118 119 120
/* dsi pll */
struct msm_dsi_pll;
#ifdef CONFIG_DRM_MSM_DSI_PLL
struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev,
			enum msm_dsi_phy_type type, int dsi_id);
void msm_dsi_pll_destroy(struct msm_dsi_pll *pll);
int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
	struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
121 122
void msm_dsi_pll_save_state(struct msm_dsi_pll *pll);
int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
123 124
int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
			    enum msm_dsi_phy_usecase uc);
125 126 127 128 129 130 131 132 133 134 135 136 137
#else
static inline struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev,
			 enum msm_dsi_phy_type type, int id) {
	return ERR_PTR(-ENODEV);
}
static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll)
{
}
static inline int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
	struct clk **byte_clk_provider, struct clk **pixel_clk_provider)
{
	return -ENODEV;
}
138 139 140 141 142 143 144
static inline void msm_dsi_pll_save_state(struct msm_dsi_pll *pll)
{
}
static inline int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll)
{
	return 0;
}
145 146 147 148 149
static inline int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
					  enum msm_dsi_phy_usecase uc)
{
	return -ENODEV;
}
150 151
#endif

152
/* dsi host */
153
struct msm_dsi_host;
154 155 156 157 158 159 160 161 162
int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
					const struct mipi_dsi_msg *msg);
void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
					const struct mipi_dsi_msg *msg);
int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
					const struct mipi_dsi_msg *msg);
int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
					const struct mipi_dsi_msg *msg);
void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
163
					u32 dma_base, u32 len);
164 165
int msm_dsi_host_enable(struct mipi_dsi_host *host);
int msm_dsi_host_disable(struct mipi_dsi_host *host);
166
int msm_dsi_host_power_on(struct mipi_dsi_host *host,
167 168
			struct msm_dsi_phy_shared_timings *phy_shared_timings,
			bool is_dual_dsi);
169 170 171 172 173
int msm_dsi_host_power_off(struct mipi_dsi_host *host);
int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
					struct drm_display_mode *mode);
struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host,
					unsigned long *panel_flags);
174
struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host);
175 176
int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer);
void msm_dsi_host_unregister(struct mipi_dsi_host *host);
177 178
int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
			struct msm_dsi_pll *src_pll);
179
void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
180
void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
181 182
	struct msm_dsi_phy_clk_request *clk_req,
	bool is_dual_dsi);
183 184 185 186
void msm_dsi_host_destroy(struct mipi_dsi_host *host);
int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
					struct drm_device *dev);
int msm_dsi_host_init(struct msm_dsi *msm_dsi);
187 188
int msm_dsi_runtime_suspend(struct device *dev);
int msm_dsi_runtime_resume(struct device *dev);
189 190 191 192 193 194 195 196 197 198 199 200 201
int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
void *dsi_tx_buf_get_v2(struct msm_dsi_host *msm_host);
void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host);
int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *iova);
int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *iova);
int dsi_clk_init_v2(struct msm_dsi_host *msm_host);
int dsi_clk_init_6g_v2(struct msm_dsi_host *msm_host);
202 203
int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_dual_dsi);
int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_dual_dsi);
204 205 206

/* dsi phy */
struct msm_dsi_phy;
207 208 209 210 211
struct msm_dsi_phy_shared_timings {
	u32 clk_post;
	u32 clk_pre;
	bool clk_pre_inc_by_2;
};
212 213 214 215 216 217

struct msm_dsi_phy_clk_request {
	unsigned long bitclk_rate;
	unsigned long escclk_rate;
};

218 219
void msm_dsi_phy_driver_register(void);
void msm_dsi_phy_driver_unregister(void);
220
int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
221
			struct msm_dsi_phy_clk_request *clk_req);
222
void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
223 224
void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy *phy,
			struct msm_dsi_phy_shared_timings *shared_timing);
225
struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy);
H
Hai Li 已提交
226 227
void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
			     enum msm_dsi_phy_usecase uc);
228

229 230
#endif /* __DSI_CONNECTOR_H__ */