1/*
2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 */
13
14#ifndef __DSI_CONNECTOR_H__
15#define __DSI_CONNECTOR_H__
16
17#include <linux/platform_device.h>
18
19#include "drm_crtc.h"
20#include "drm_mipi_dsi.h"
21#include "drm_panel.h"
22
23#include "msm_drv.h"
24
25#define DSI_0	0
26#define DSI_1	1
27#define DSI_MAX	2
28
29#define DSI_CLOCK_MASTER	DSI_0
30#define DSI_CLOCK_SLAVE		DSI_1
31
32#define DSI_LEFT		DSI_0
33#define DSI_RIGHT		DSI_1
34
35/* According to the current drm framework sequence, take the encoder of
36 * DSI_1 as master encoder
37 */
38#define DSI_ENCODER_MASTER	DSI_1
39#define DSI_ENCODER_SLAVE	DSI_0
40
41struct msm_dsi {
42	struct drm_device *dev;
43	struct platform_device *pdev;
44
45	struct drm_connector *connector;
46	struct drm_bridge *bridge;
47
48	struct mipi_dsi_host *host;
49	struct msm_dsi_phy *phy;
50	struct drm_panel *panel;
51	unsigned long panel_flags;
52	bool phy_enabled;
53
54	/* the encoders we are hooked to (outside of dsi block) */
55	struct drm_encoder *encoders[MSM_DSI_ENCODER_NUM];
56
57	int id;
58};
59
60/* dsi manager */
61struct drm_bridge *msm_dsi_manager_bridge_init(u8 id);
62void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge);
63struct drm_connector *msm_dsi_manager_connector_init(u8 id);
64int msm_dsi_manager_phy_enable(int id,
65		const unsigned long bit_rate, const unsigned long esc_rate,
66		u32 *clk_pre, u32 *clk_post);
67void msm_dsi_manager_phy_disable(int id);
68int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
69bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 iova, u32 len);
70int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
71void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
72
73/* msm dsi */
74struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);
75
76/* dsi host */
77int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
78					const struct mipi_dsi_msg *msg);
79void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
80					const struct mipi_dsi_msg *msg);
81int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
82					const struct mipi_dsi_msg *msg);
83int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
84					const struct mipi_dsi_msg *msg);
85void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
86					u32 iova, u32 len);
87int msm_dsi_host_enable(struct mipi_dsi_host *host);
88int msm_dsi_host_disable(struct mipi_dsi_host *host);
89int msm_dsi_host_power_on(struct mipi_dsi_host *host);
90int msm_dsi_host_power_off(struct mipi_dsi_host *host);
91int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
92					struct drm_display_mode *mode);
93struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host,
94					unsigned long *panel_flags);
95int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer);
96void msm_dsi_host_unregister(struct mipi_dsi_host *host);
97void msm_dsi_host_destroy(struct mipi_dsi_host *host);
98int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
99					struct drm_device *dev);
100int msm_dsi_host_init(struct msm_dsi *msm_dsi);
101
102/* dsi phy */
103struct msm_dsi_phy;
104enum msm_dsi_phy_type {
105	MSM_DSI_PHY_UNKNOWN,
106	MSM_DSI_PHY_28NM,
107	MSM_DSI_PHY_MAX
108};
109struct msm_dsi_phy *msm_dsi_phy_init(struct platform_device *pdev,
110			enum msm_dsi_phy_type type, int id);
111int msm_dsi_phy_enable(struct msm_dsi_phy *phy, bool is_dual_panel,
112	const unsigned long bit_rate, const unsigned long esc_rate);
113int msm_dsi_phy_disable(struct msm_dsi_phy *phy);
114void msm_dsi_phy_get_clk_pre_post(struct msm_dsi_phy *phy,
115					u32 *clk_pre, u32 *clk_post);
116#endif /* __DSI_CONNECTOR_H__ */
117
118