]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/msm/hdmi/hdmi.h
WIP: drm: msm: add proper hdmi codec driver.
[karo-tx-linux.git] / drivers / gpu / drm / msm / hdmi / hdmi.h
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_hdcp_ctrl;
41
42 struct hdmi {
43         struct drm_device *dev;
44         struct platform_device *pdev;
45         struct platform_device *audio_pdev;
46
47         const struct hdmi_platform_config *config;
48
49         /* audio state: */
50         struct hdmi_audio audio;
51
52         /* video state: */
53         bool power_on;
54         unsigned long int pixclock;
55
56         void __iomem *mmio;
57         void __iomem *qfprom_mmio;
58         phys_addr_t mmio_phy_addr;
59
60         struct regulator **hpd_regs;
61         struct regulator **pwr_regs;
62         struct clk **hpd_clks;
63         struct clk **pwr_clks;
64
65         struct hdmi_phy *phy;
66         struct i2c_adapter *i2c;
67         struct drm_connector *connector;
68         struct drm_bridge *bridge;
69
70         /* the encoder we are hooked to (outside of hdmi block) */
71         struct drm_encoder *encoder;
72
73         bool hdmi_mode;               /* are we in hdmi mode? */
74
75         int irq;
76         struct workqueue_struct *workq;
77
78         struct hdmi_hdcp_ctrl *hdcp_ctrl;
79
80         /*
81         * spinlock to protect registers shared by different execution
82         * REG_HDMI_CTRL
83         * REG_HDMI_DDC_ARBITRATION
84         * REG_HDMI_HDCP_INT_CTRL
85         * REG_HDMI_HPD_CTRL
86         */
87         spinlock_t reg_lock;
88 };
89
90 /* platform config data (ie. from DT, or pdata) */
91 struct hdmi_platform_config {
92         struct hdmi_phy *(*phy_init)(struct hdmi *hdmi);
93         const char *mmio_name;
94         const char *qfprom_mmio_name;
95
96         /* regulators that need to be on for hpd: */
97         const char **hpd_reg_names;
98         int hpd_reg_cnt;
99
100         /* regulators that need to be on for screen pwr: */
101         const char **pwr_reg_names;
102         int pwr_reg_cnt;
103
104         /* clks that need to be on for hpd: */
105         const char **hpd_clk_names;
106         const long unsigned *hpd_freq;
107         int hpd_clk_cnt;
108
109         /* clks that need to be on for screen pwr (ie pixel clk): */
110         const char **pwr_clk_names;
111         int pwr_clk_cnt;
112
113         /* gpio's: */
114         int ddc_clk_gpio, ddc_data_gpio, hpd_gpio, mux_en_gpio, mux_sel_gpio;
115         int mux_lpm_gpio;
116 };
117
118 void hdmi_set_mode(struct hdmi *hdmi, bool power_on);
119
120 static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
121 {
122         msm_writel(data, hdmi->mmio + reg);
123 }
124
125 static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
126 {
127         return msm_readl(hdmi->mmio + reg);
128 }
129
130 static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
131 {
132         return msm_readl(hdmi->qfprom_mmio + reg);
133 }
134
135 /*
136  * The phy appears to be different, for example between 8960 and 8x60,
137  * so split the phy related functions out and load the correct one at
138  * runtime:
139  */
140
141 struct hdmi_phy_funcs {
142         void (*destroy)(struct hdmi_phy *phy);
143         void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
144         void (*powerdown)(struct hdmi_phy *phy);
145 };
146
147 struct hdmi_phy {
148         const struct hdmi_phy_funcs *funcs;
149 };
150
151 struct hdmi_phy *hdmi_phy_8960_init(struct hdmi *hdmi);
152 struct hdmi_phy *hdmi_phy_8x60_init(struct hdmi *hdmi);
153 struct hdmi_phy *hdmi_phy_8x74_init(struct hdmi *hdmi);
154
155 /*
156  * audio:
157  */
158
159 int hdmi_audio_update(struct hdmi *hdmi);
160 int hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
161         uint32_t num_of_channels, uint32_t channel_allocation,
162         uint32_t level_shift, bool down_mix);
163 void hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
164
165
166 /*
167  * hdmi bridge:
168  */
169
170 struct drm_bridge *hdmi_bridge_init(struct hdmi *hdmi);
171 void hdmi_bridge_destroy(struct drm_bridge *bridge);
172
173 /*
174  * hdmi connector:
175  */
176
177 void hdmi_connector_irq(struct drm_connector *connector);
178 struct drm_connector *hdmi_connector_init(struct hdmi *hdmi);
179
180 /*
181  * i2c adapter for ddc:
182  */
183
184 void hdmi_i2c_irq(struct i2c_adapter *i2c);
185 void hdmi_i2c_destroy(struct i2c_adapter *i2c);
186 struct i2c_adapter *hdmi_i2c_init(struct hdmi *hdmi);
187
188 /*
189  * hdcp
190  */
191 struct hdmi_hdcp_ctrl *hdmi_hdcp_init(struct hdmi *hdmi);
192 void hdmi_hdcp_destroy(struct hdmi *hdmi);
193 void hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
194 void hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
195 void hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
196
197 #endif /* __HDMI_CONNECTOR_H__ */