xref: /linux/drivers/gpu/drm/msm/hdmi/hdmi.h (revision 93df8a1ed6231727c5db94a80b1a6bd5ee67cec3)
1 /*
2  * Copyright (C) 2013 Red Hat
3  * Author: Rob Clark <robdclark@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __HDMI_CONNECTOR_H__
19 #define __HDMI_CONNECTOR_H__
20 
21 #include <linux/i2c.h>
22 #include <linux/clk.h>
23 #include <linux/platform_device.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/hdmi.h>
26 
27 #include "msm_drv.h"
28 #include "hdmi.xml.h"
29 
30 
31 struct hdmi_phy;
32 struct hdmi_platform_config;
33 
34 struct hdmi_audio {
35 	bool enabled;
36 	struct hdmi_audio_infoframe infoframe;
37 	int rate;
38 };
39 
40 struct hdmi {
41 	struct drm_device *dev;
42 	struct platform_device *pdev;
43 
44 	const struct hdmi_platform_config *config;
45 
46 	/* audio state: */
47 	struct hdmi_audio audio;
48 
49 	/* video state: */
50 	bool power_on;
51 	unsigned long int pixclock;
52 
53 	void __iomem *mmio;
54 
55 	struct regulator **hpd_regs;
56 	struct regulator **pwr_regs;
57 	struct clk **hpd_clks;
58 	struct clk **pwr_clks;
59 
60 	struct hdmi_phy *phy;
61 	struct i2c_adapter *i2c;
62 	struct drm_connector *connector;
63 	struct drm_bridge *bridge;
64 
65 	/* the encoder we are hooked to (outside of hdmi block) */
66 	struct drm_encoder *encoder;
67 
68 	bool hdmi_mode;               /* are we in hdmi mode? */
69 
70 	int irq;
71 };
72 
73 /* platform config data (ie. from DT, or pdata) */
74 struct hdmi_platform_config {
75 	struct hdmi_phy *(*phy_init)(struct hdmi *hdmi);
76 	const char *mmio_name;
77 
78 	/* regulators that need to be on for hpd: */
79 	const char **hpd_reg_names;
80 	int hpd_reg_cnt;
81 
82 	/* regulators that need to be on for screen pwr: */
83 	const char **pwr_reg_names;
84 	int pwr_reg_cnt;
85 
86 	/* clks that need to be on for hpd: */
87 	const char **hpd_clk_names;
88 	const long unsigned *hpd_freq;
89 	int hpd_clk_cnt;
90 
91 	/* clks that need to be on for screen pwr (ie pixel clk): */
92 	const char **pwr_clk_names;
93 	int pwr_clk_cnt;
94 
95 	/* gpio's: */
96 	int ddc_clk_gpio, ddc_data_gpio, hpd_gpio, mux_en_gpio, mux_sel_gpio;
97 	int mux_lpm_gpio;
98 };
99 
100 void hdmi_set_mode(struct hdmi *hdmi, bool power_on);
101 
102 static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
103 {
104 	msm_writel(data, hdmi->mmio + reg);
105 }
106 
107 static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
108 {
109 	return msm_readl(hdmi->mmio + reg);
110 }
111 
112 /*
113  * The phy appears to be different, for example between 8960 and 8x60,
114  * so split the phy related functions out and load the correct one at
115  * runtime:
116  */
117 
118 struct hdmi_phy_funcs {
119 	void (*destroy)(struct hdmi_phy *phy);
120 	void (*reset)(struct hdmi_phy *phy);
121 	void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
122 	void (*powerdown)(struct hdmi_phy *phy);
123 };
124 
125 struct hdmi_phy {
126 	const struct hdmi_phy_funcs *funcs;
127 };
128 
129 struct hdmi_phy *hdmi_phy_8960_init(struct hdmi *hdmi);
130 struct hdmi_phy *hdmi_phy_8x60_init(struct hdmi *hdmi);
131 struct hdmi_phy *hdmi_phy_8x74_init(struct hdmi *hdmi);
132 
133 /*
134  * audio:
135  */
136 
137 int hdmi_audio_update(struct hdmi *hdmi);
138 int hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
139 	uint32_t num_of_channels, uint32_t channel_allocation,
140 	uint32_t level_shift, bool down_mix);
141 void hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
142 
143 
144 /*
145  * hdmi bridge:
146  */
147 
148 struct drm_bridge *hdmi_bridge_init(struct hdmi *hdmi);
149 void hdmi_bridge_destroy(struct drm_bridge *bridge);
150 
151 /*
152  * hdmi connector:
153  */
154 
155 void hdmi_connector_irq(struct drm_connector *connector);
156 struct drm_connector *hdmi_connector_init(struct hdmi *hdmi);
157 
158 /*
159  * i2c adapter for ddc:
160  */
161 
162 void hdmi_i2c_irq(struct i2c_adapter *i2c);
163 void hdmi_i2c_destroy(struct i2c_adapter *i2c);
164 struct i2c_adapter *hdmi_i2c_init(struct hdmi *hdmi);
165 
166 #endif /* __HDMI_CONNECTOR_H__ */
167