blob: d71533219877e4519d8dcdf8509432be99258d39 [file] [log] [blame]
Rob Clarkc8afe682013-06-26 12:44:06 -04001/*
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>
Rob Clarkc0c0d9e2013-12-11 14:44:02 -050025#include <linux/hdmi.h>
Rob Clarkc8afe682013-06-26 12:44:06 -040026
27#include "msm_drv.h"
28#include "hdmi.xml.h"
29
Archit Tanejadc50f7822016-02-25 11:22:36 +053030#define HDMI_MAX_NUM_GPIO 6
Rob Clarkc8afe682013-06-26 12:44:06 -040031
32struct hdmi_phy;
Rob Clarkdada25b2013-12-01 12:12:54 -050033struct hdmi_platform_config;
Rob Clarkc8afe682013-06-26 12:44:06 -040034
Archit Tanejadc50f7822016-02-25 11:22:36 +053035struct hdmi_gpio_data {
36 int num;
37 bool output;
38 int value;
39 const char *label;
40};
41
Rob Clarkc0c0d9e2013-12-11 14:44:02 -050042struct hdmi_audio {
43 bool enabled;
44 struct hdmi_audio_infoframe infoframe;
45 int rate;
46};
47
jilai wangc6a57a52015-04-02 17:49:01 -040048struct hdmi_hdcp_ctrl;
49
Rob Clarkc8afe682013-06-26 12:44:06 -040050struct hdmi {
51 struct drm_device *dev;
52 struct platform_device *pdev;
53
Rob Clarkdada25b2013-12-01 12:12:54 -050054 const struct hdmi_platform_config *config;
55
Rob Clarkc0c0d9e2013-12-11 14:44:02 -050056 /* audio state: */
57 struct hdmi_audio audio;
58
59 /* video state: */
60 bool power_on;
61 unsigned long int pixclock;
62
Rob Clarkc8afe682013-06-26 12:44:06 -040063 void __iomem *mmio;
jilai wangc6a57a52015-04-02 17:49:01 -040064 void __iomem *qfprom_mmio;
65 phys_addr_t mmio_phy_addr;
Rob Clarkc8afe682013-06-26 12:44:06 -040066
Stephane Viau447fa522015-01-13 14:33:40 -050067 struct regulator **hpd_regs;
68 struct regulator **pwr_regs;
69 struct clk **hpd_clks;
70 struct clk **pwr_clks;
Rob Clarkc8afe682013-06-26 12:44:06 -040071
72 struct hdmi_phy *phy;
73 struct i2c_adapter *i2c;
74 struct drm_connector *connector;
Rob Clarka3376e32013-08-30 13:02:15 -040075 struct drm_bridge *bridge;
76
77 /* the encoder we are hooked to (outside of hdmi block) */
78 struct drm_encoder *encoder;
Rob Clarkc8afe682013-06-26 12:44:06 -040079
80 bool hdmi_mode; /* are we in hdmi mode? */
81
82 int irq;
jilai wangc6a57a52015-04-02 17:49:01 -040083 struct workqueue_struct *workq;
84
85 struct hdmi_hdcp_ctrl *hdcp_ctrl;
86
87 /*
88 * spinlock to protect registers shared by different execution
89 * REG_HDMI_CTRL
90 * REG_HDMI_DDC_ARBITRATION
91 * REG_HDMI_HDCP_INT_CTRL
92 * REG_HDMI_HPD_CTRL
93 */
94 spinlock_t reg_lock;
Rob Clarkc8afe682013-06-26 12:44:06 -040095};
96
97/* platform config data (ie. from DT, or pdata) */
98struct hdmi_platform_config {
99 struct hdmi_phy *(*phy_init)(struct hdmi *hdmi);
Rob Clarkdada25b2013-12-01 12:12:54 -0500100 const char *mmio_name;
jilai wangc6a57a52015-04-02 17:49:01 -0400101 const char *qfprom_mmio_name;
Rob Clarkdada25b2013-12-01 12:12:54 -0500102
103 /* regulators that need to be on for hpd: */
104 const char **hpd_reg_names;
105 int hpd_reg_cnt;
106
107 /* regulators that need to be on for screen pwr: */
108 const char **pwr_reg_names;
109 int pwr_reg_cnt;
110
111 /* clks that need to be on for hpd: */
112 const char **hpd_clk_names;
Stephane Viaub77f47e2014-06-06 10:03:32 -0400113 const long unsigned *hpd_freq;
Rob Clarkdada25b2013-12-01 12:12:54 -0500114 int hpd_clk_cnt;
115
116 /* clks that need to be on for screen pwr (ie pixel clk): */
117 const char **pwr_clk_names;
118 int pwr_clk_cnt;
119
120 /* gpio's: */
Archit Tanejadc50f7822016-02-25 11:22:36 +0530121 struct hdmi_gpio_data gpios[HDMI_MAX_NUM_GPIO];
Rob Clarkc8afe682013-06-26 12:44:06 -0400122};
123
124void hdmi_set_mode(struct hdmi *hdmi, bool power_on);
Rob Clarkc8afe682013-06-26 12:44:06 -0400125
126static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
127{
128 msm_writel(data, hdmi->mmio + reg);
129}
130
131static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
132{
133 return msm_readl(hdmi->mmio + reg);
134}
135
jilai wangc6a57a52015-04-02 17:49:01 -0400136static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
137{
138 return msm_readl(hdmi->qfprom_mmio + reg);
139}
140
Rob Clarkc8afe682013-06-26 12:44:06 -0400141/*
142 * The phy appears to be different, for example between 8960 and 8x60,
143 * so split the phy related functions out and load the correct one at
144 * runtime:
145 */
146
147struct hdmi_phy_funcs {
148 void (*destroy)(struct hdmi_phy *phy);
Rob Clarkc8afe682013-06-26 12:44:06 -0400149 void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
150 void (*powerdown)(struct hdmi_phy *phy);
151};
152
153struct hdmi_phy {
154 const struct hdmi_phy_funcs *funcs;
155};
156
Rob Clarkc8afe682013-06-26 12:44:06 -0400157struct hdmi_phy *hdmi_phy_8960_init(struct hdmi *hdmi);
158struct hdmi_phy *hdmi_phy_8x60_init(struct hdmi *hdmi);
Rob Clarkdada25b2013-12-01 12:12:54 -0500159struct hdmi_phy *hdmi_phy_8x74_init(struct hdmi *hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -0400160
161/*
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500162 * audio:
163 */
164
165int hdmi_audio_update(struct hdmi *hdmi);
166int hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
167 uint32_t num_of_channels, uint32_t channel_allocation,
168 uint32_t level_shift, bool down_mix);
169void hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
170
171
172/*
Rob Clarka3376e32013-08-30 13:02:15 -0400173 * hdmi bridge:
174 */
175
176struct drm_bridge *hdmi_bridge_init(struct hdmi *hdmi);
Ajay Kumar3d3f8b12015-01-20 22:08:44 +0530177void hdmi_bridge_destroy(struct drm_bridge *bridge);
Rob Clarka3376e32013-08-30 13:02:15 -0400178
179/*
Rob Clarkc8afe682013-06-26 12:44:06 -0400180 * hdmi connector:
181 */
182
183void hdmi_connector_irq(struct drm_connector *connector);
Rob Clarka3376e32013-08-30 13:02:15 -0400184struct drm_connector *hdmi_connector_init(struct hdmi *hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -0400185
186/*
187 * i2c adapter for ddc:
188 */
189
190void hdmi_i2c_irq(struct i2c_adapter *i2c);
191void hdmi_i2c_destroy(struct i2c_adapter *i2c);
192struct i2c_adapter *hdmi_i2c_init(struct hdmi *hdmi);
193
jilai wangc6a57a52015-04-02 17:49:01 -0400194/*
195 * hdcp
196 */
197struct hdmi_hdcp_ctrl *hdmi_hdcp_init(struct hdmi *hdmi);
198void hdmi_hdcp_destroy(struct hdmi *hdmi);
199void hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
200void hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
201void hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
202
Rob Clarkc8afe682013-06-26 12:44:06 -0400203#endif /* __HDMI_CONNECTOR_H__ */