blob: accc9a61611d35bf9718d66fe09ce6c6e40a549f [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;
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +010053 struct platform_device *audio_pdev;
Rob Clarkc8afe682013-06-26 12:44:06 -040054
Rob Clarkdada25b2013-12-01 12:12:54 -050055 const struct hdmi_platform_config *config;
56
Rob Clarkc0c0d9e2013-12-11 14:44:02 -050057 /* audio state: */
58 struct hdmi_audio audio;
59
60 /* video state: */
61 bool power_on;
62 unsigned long int pixclock;
63
Rob Clarkc8afe682013-06-26 12:44:06 -040064 void __iomem *mmio;
jilai wangc6a57a52015-04-02 17:49:01 -040065 void __iomem *qfprom_mmio;
66 phys_addr_t mmio_phy_addr;
Rob Clarkc8afe682013-06-26 12:44:06 -040067
Stephane Viau447fa522015-01-13 14:33:40 -050068 struct regulator **hpd_regs;
69 struct regulator **pwr_regs;
70 struct clk **hpd_clks;
71 struct clk **pwr_clks;
Rob Clarkc8afe682013-06-26 12:44:06 -040072
73 struct hdmi_phy *phy;
Archit Tanejae00012b2016-02-25 11:22:40 +053074 struct device *phy_dev;
75
Rob Clarkc8afe682013-06-26 12:44:06 -040076 struct i2c_adapter *i2c;
77 struct drm_connector *connector;
Rob Clarka3376e32013-08-30 13:02:15 -040078 struct drm_bridge *bridge;
79
80 /* the encoder we are hooked to (outside of hdmi block) */
81 struct drm_encoder *encoder;
Rob Clarkc8afe682013-06-26 12:44:06 -040082
83 bool hdmi_mode; /* are we in hdmi mode? */
84
85 int irq;
jilai wangc6a57a52015-04-02 17:49:01 -040086 struct workqueue_struct *workq;
87
88 struct hdmi_hdcp_ctrl *hdcp_ctrl;
89
90 /*
91 * spinlock to protect registers shared by different execution
92 * REG_HDMI_CTRL
93 * REG_HDMI_DDC_ARBITRATION
94 * REG_HDMI_HDCP_INT_CTRL
95 * REG_HDMI_HPD_CTRL
96 */
97 spinlock_t reg_lock;
Rob Clarkc8afe682013-06-26 12:44:06 -040098};
99
100/* platform config data (ie. from DT, or pdata) */
101struct hdmi_platform_config {
Rob Clarkdada25b2013-12-01 12:12:54 -0500102 const char *mmio_name;
jilai wangc6a57a52015-04-02 17:49:01 -0400103 const char *qfprom_mmio_name;
Rob Clarkdada25b2013-12-01 12:12:54 -0500104
105 /* regulators that need to be on for hpd: */
106 const char **hpd_reg_names;
107 int hpd_reg_cnt;
108
109 /* regulators that need to be on for screen pwr: */
110 const char **pwr_reg_names;
111 int pwr_reg_cnt;
112
113 /* clks that need to be on for hpd: */
114 const char **hpd_clk_names;
Stephane Viaub77f47e2014-06-06 10:03:32 -0400115 const long unsigned *hpd_freq;
Rob Clarkdada25b2013-12-01 12:12:54 -0500116 int hpd_clk_cnt;
117
118 /* clks that need to be on for screen pwr (ie pixel clk): */
119 const char **pwr_clk_names;
120 int pwr_clk_cnt;
121
122 /* gpio's: */
Archit Tanejadc50f7822016-02-25 11:22:36 +0530123 struct hdmi_gpio_data gpios[HDMI_MAX_NUM_GPIO];
Rob Clarkc8afe682013-06-26 12:44:06 -0400124};
125
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100126void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on);
Rob Clarkc8afe682013-06-26 12:44:06 -0400127
128static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
129{
130 msm_writel(data, hdmi->mmio + reg);
131}
132
133static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
134{
135 return msm_readl(hdmi->mmio + reg);
136}
137
jilai wangc6a57a52015-04-02 17:49:01 -0400138static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
139{
140 return msm_readl(hdmi->qfprom_mmio + reg);
141}
142
Rob Clarkc8afe682013-06-26 12:44:06 -0400143/*
Archit Taneja15b4a452016-02-25 11:22:38 +0530144 * hdmi phy:
Rob Clarkc8afe682013-06-26 12:44:06 -0400145 */
Rob Clarkc8afe682013-06-26 12:44:06 -0400146
Archit Taneja15b4a452016-02-25 11:22:38 +0530147enum hdmi_phy_type {
148 MSM_HDMI_PHY_8x60,
149 MSM_HDMI_PHY_8960,
150 MSM_HDMI_PHY_8x74,
Archit Tanejae17afdc2016-02-25 11:22:44 +0530151 MSM_HDMI_PHY_8996,
Archit Taneja15b4a452016-02-25 11:22:38 +0530152 MSM_HDMI_PHY_MAX,
153};
154
155struct hdmi_phy_cfg {
156 enum hdmi_phy_type type;
157 void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
158 void (*powerdown)(struct hdmi_phy *phy);
159 const char * const *reg_names;
160 int num_regs;
161 const char * const *clk_names;
162 int num_clks;
163};
164
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100165extern const struct hdmi_phy_cfg msm_hdmi_phy_8x60_cfg;
166extern const struct hdmi_phy_cfg msm_hdmi_phy_8960_cfg;
167extern const struct hdmi_phy_cfg msm_hdmi_phy_8x74_cfg;
168extern const struct hdmi_phy_cfg msm_hdmi_phy_8996_cfg;
Archit Taneja15b4a452016-02-25 11:22:38 +0530169
Rob Clarkc8afe682013-06-26 12:44:06 -0400170struct hdmi_phy {
Archit Taneja15b4a452016-02-25 11:22:38 +0530171 struct platform_device *pdev;
172 void __iomem *mmio;
173 struct hdmi_phy_cfg *cfg;
Rob Clarkc8afe682013-06-26 12:44:06 -0400174 const struct hdmi_phy_funcs *funcs;
Archit Taneja15b4a452016-02-25 11:22:38 +0530175 struct regulator **regs;
176 struct clk **clks;
Rob Clarkc8afe682013-06-26 12:44:06 -0400177};
178
Archit Taneja15b4a452016-02-25 11:22:38 +0530179static inline void hdmi_phy_write(struct hdmi_phy *phy, u32 reg, u32 data)
180{
181 msm_writel(data, phy->mmio + reg);
182}
183
184static inline u32 hdmi_phy_read(struct hdmi_phy *phy, u32 reg)
185{
186 return msm_readl(phy->mmio + reg);
187}
188
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100189int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy);
190void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy);
191void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock);
192void msm_hdmi_phy_powerdown(struct hdmi_phy *phy);
193void __init msm_hdmi_phy_driver_register(void);
194void __exit msm_hdmi_phy_driver_unregister(void);
Archit Taneja15b4a452016-02-25 11:22:38 +0530195
Archit Tanejaea184892016-02-25 11:22:39 +0530196#ifdef CONFIG_COMMON_CLK
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100197int msm_hdmi_pll_8960_init(struct platform_device *pdev);
198int msm_hdmi_pll_8996_init(struct platform_device *pdev);
Archit Tanejaea184892016-02-25 11:22:39 +0530199#else
Rob Clark0a695092016-03-23 10:09:00 -0400200static inline int msm_hdmi_pll_8960_init(struct platform_device *pdev)
Archit Tanejaea184892016-02-25 11:22:39 +0530201{
202 return -ENODEV;
203}
Archit Tanejae17afdc2016-02-25 11:22:44 +0530204
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100205static inline int msm_hdmi_pll_8996_init(struct platform_device *pdev)
Archit Tanejae17afdc2016-02-25 11:22:44 +0530206{
207 return -ENODEV;
208}
Archit Tanejaea184892016-02-25 11:22:39 +0530209#endif
210
Rob Clarkc8afe682013-06-26 12:44:06 -0400211/*
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500212 * audio:
213 */
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100214/* Supported HDMI Audio channels and rates */
215#define MSM_HDMI_AUDIO_CHANNEL_2 0
216#define MSM_HDMI_AUDIO_CHANNEL_4 1
217#define MSM_HDMI_AUDIO_CHANNEL_6 2
218#define MSM_HDMI_AUDIO_CHANNEL_8 3
219
220#define HDMI_SAMPLE_RATE_32KHZ 0
221#define HDMI_SAMPLE_RATE_44_1KHZ 1
222#define HDMI_SAMPLE_RATE_48KHZ 2
223#define HDMI_SAMPLE_RATE_88_2KHZ 3
224#define HDMI_SAMPLE_RATE_96KHZ 4
225#define HDMI_SAMPLE_RATE_176_4KHZ 5
226#define HDMI_SAMPLE_RATE_192KHZ 6
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500227
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100228int msm_hdmi_audio_update(struct hdmi *hdmi);
229int msm_hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500230 uint32_t num_of_channels, uint32_t channel_allocation,
231 uint32_t level_shift, bool down_mix);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100232void msm_hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500233
234
235/*
Rob Clarka3376e32013-08-30 13:02:15 -0400236 * hdmi bridge:
237 */
238
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100239struct drm_bridge *msm_hdmi_bridge_init(struct hdmi *hdmi);
240void msm_hdmi_bridge_destroy(struct drm_bridge *bridge);
Rob Clarka3376e32013-08-30 13:02:15 -0400241
242/*
Rob Clarkc8afe682013-06-26 12:44:06 -0400243 * hdmi connector:
244 */
245
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100246void msm_hdmi_connector_irq(struct drm_connector *connector);
247struct drm_connector *msm_hdmi_connector_init(struct hdmi *hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -0400248
249/*
250 * i2c adapter for ddc:
251 */
252
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100253void msm_hdmi_i2c_irq(struct i2c_adapter *i2c);
254void msm_hdmi_i2c_destroy(struct i2c_adapter *i2c);
255struct i2c_adapter *msm_hdmi_i2c_init(struct hdmi *hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -0400256
jilai wangc6a57a52015-04-02 17:49:01 -0400257/*
258 * hdcp
259 */
Rob Clarkfeb46f02016-03-20 10:16:29 -0400260#ifdef CONFIG_DRM_MSM_HDMI_HDCP
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100261struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi);
262void msm_hdmi_hdcp_destroy(struct hdmi *hdmi);
263void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
264void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
265void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
Rob Clarkfeb46f02016-03-20 10:16:29 -0400266#else
267static inline struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi)
268{
269 return ERR_PTR(-ENXIO);
270}
271static inline void msm_hdmi_hdcp_destroy(struct hdmi *hdmi) {}
272static inline void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
273static inline void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
274static inline void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
275#endif
jilai wangc6a57a52015-04-02 17:49:01 -0400276
Rob Clarkc8afe682013-06-26 12:44:06 -0400277#endif /* __HDMI_CONNECTOR_H__ */